View Full Version : Insert text to be displayed on site
jamesh_1993
08-04-2008, 09:19 PM
Firstly, Hi everyone. As you can probably see, I'm new and no good at coding myself. I have used Dynamic Drive cos they have some pretty neat stuff.
My question is, is there any way a visitor on my site could type his/her name in a text input box, hit enter, and it comes up at the top of the page saying "Hello! name" Personalizing the header.
I know it sounds a daft question (or it is worded wrong) but thanks in advance.
TheJoshMan
08-04-2008, 10:19 PM
I know it can be done with a "shell" script. I'm sure it can probably be accomplished via Javascript and/or PHP as well... Here is a link to check out.
http://bash.cyberciti.biz/academic/ask-user-name/
rangana
08-05-2008, 01:03 AM
Here's a Javascript counterpart:
<script type="text/javascript">
window.onload=function(){
document.getElementById('enter').onclick=function(){
document.getElementById('show').innerHTML='Hello <span style="color:#930;">'+document.getElementById('urName').value+'</span> Welcome!';}}
</script>
<div id="show" style="font-family:Arial,helvetica,serif;font-size:15pt;"></div>
<label for="urName">Name: </label><input type="text" id="urName">
<input type="button" value="Enter" id="enter">
and a PHP one:
<?php
if(ISSET($_POST['urName']))
echo '<div id="show" style="font-family:Arial,helvetica,serif;font-size:15pt;">Hello <span style="color:#930;">'.$_POST['urName'].'</span> Welcome!</div>';
?>
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<label for="urName">Name: </label><input type="text" id="urName" name="urName">
<input type="submit" value="Enter">
</form>
Hope this gives you a variety of choices.
TheJoshMan
08-05-2008, 01:05 AM
Now if we could just figure out a way to give them an HTML version... They'd be all set! lol
jamesh_1993
08-05-2008, 09:49 AM
Here's a Javascript counterpart:
<script type="text/javascript">
window.onload=function(){
document.getElementById('enter').onclick=function(){
document.getElementById('show').innerHTML='Hello <span style="color:#930;">'+document.getElementById('urName').value+'</span> Welcome!';}}
</script>
<div id="show" style="font-family:Arial,helvetica,serif;font-size:15pt;"></div>
<label for="urName">Name: </label><input type="text" id="urName">
<input type="button" value="Enter" id="enter">
and a PHP one:
<?php
if(ISSET($_POST['urName']))
echo '<div id="show" style="font-family:Arial,helvetica,serif;font-size:15pt;">Hello <span style="color:#930;">'.$_POST['urName'].'</span> Welcome!</div>';
?>
<form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<label for="urName">Name: </label><input type="text" id="urName" name="urName">
<input type="submit" value="Enter">
</form>
Hope this gives you a variety of choices.
Thanks for that. I'm not great with coding and stuff, so i just put this under the HTML Thread.
(Y)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.