By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,500 Members | 1,238 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,500 IT Pros & Developers. It's quick & easy.

Page wont work when I add form tags!

P: 17
Hey.
I was trying to write a page yesterday where an admin can register a user. I wrote some javascript so that when the forename or surnames are off focus, a script is run to take the forename and surname, concatenate them and put them in the username box as a suggestion. The code worked fine until later when I added the form tags around the inputs (forgot to do it earlier). Code below:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <title>Admin ~ Users</title>
  6. <link rel="stylesheet" href="../css/admin/users.css" />
  7. <script type="text/javascript">
  8. function username(){
  9.     if(document.getElementById('forename').value != ""){
  10.         if(document.getElementById('surname').value != ""){
  11.             name = document.getElementById('forename').value;
  12.             name = name + document.getElementById('surname').value;
  13.             name = name.toLowerCase();
  14.             document.getElementById('username').value = name;
  15.         }
  16.     }
  17. }
  18. </script>
  19. </head>
  20.  
  21. <body>
  22. <div class='error'><?PHP echo str_replace("\'", "'", $_GET['error']); ?></div>
  23. <br />
  24. <form id="adduser" action="users_new_app.php" method="post">
  25. <table>
  26. <tr>
  27.     <th>Field</th>
  28.     <th>Value</th>
  29. </tr>
  30. <tr>
  31.     <th>Forename</th>
  32.     <td><input type="text" name="forename" size="50" id="forename" /></td>
  33. </tr>
  34. <tr>
  35.     <th>Surname</th>
  36.     <td><input type="text" name="surname" size="50" id="surname" /></td>
  37. </tr>
  38. <tr>
  39.     <th>Username</th>
  40.     <td><input type="text" name="username" size="50" id="username" onfocus="javascript:username();" /></td>
  41. </tr>
  42. ....
  43. </table>
  44. </form>
  45. </body>
  46. </html>
  47.  
I can't see anything wrong with it but it only doesn't work when the form tags are there, I took them away and it worked again...but naturally I need them to send the form!
May 30 '08 #1
Share this Question
Share on Google+
3 Replies


hsriat
Expert 100+
P: 1,654
Change the name of the function to something else. eg suggestUsername()

It can't be same with an element name of a form.
May 30 '08 #2

P: 17
yip! that made it work! thank you sooo much! That was driving me nuts!

So apparently you can't have a function with the same name as an element in your form...who knew!
May 30 '08 #3

hsriat
Expert 100+
P: 1,654
yeah.. apparently... event I just came to know when I tried your code.
May 30 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.