473,473 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Page wont work when I add form tags!

17 New Member
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
3 1350
hsriat
1,654 Recognized Expert Top Contributor
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
gm04030276
17 New Member
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
1,654 Recognized Expert Top Contributor
yeah.. apparently... event I just came to know when I tried your code.
May 30 '08 #4

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

Similar topics

7
by: Noozer | last post by:
I am able to place values on forms that load into my webbrowser control, but I'd like to be able to scan the page for data. I know to use the HTMLDocument object. Basically I'm hoping to find an...
4
by: Rob Meade | last post by:
Hi all, Ok - this leads on from speaking to a couple here and in the SQL server group... I've an application which allows the user to type in their text into a form, they add 'happy' tags...
4
by: dmiller23462 | last post by:
I'm trying to create a submission page for users to request PC/LAN Access....If they select "Yes" in the field asking about if they need Non Standard Software, I want several other HTML fields to...
3
by: Matt Herson | last post by:
I am looking for a validation script that will only look at the fields in the cgi form, determine if the fields are filled out, then if one or more are blank will write a message at the top of the...
7
by: Gapingwound | last post by:
I have one page that is not validating XHTML1 STRICT properly, but the validator at w3c is showing an error for something that is not in my page. Here's the error: 1. Line 72, column 160:...
11
by: Tom | last post by:
Hi all, I posted the same question one week ago in http://communities.microsoft.com/newsgroups/previewFrame.as p? ICP=msdn&sLCID=us&sgroupURL=microsoft.public.dotnet.framewo...
4
by: Kevin Phifer | last post by:
Ok, before anyone freaks out, I have a solution I need to create that gathers content from maybe different places. Each one can return a <form> in the html, so its the classic can't have more than...
7
by: Martin | last post by:
Hi, I have a standard aspx page (form) that contains a few user controls. Upon form submission the page is validated. If validation passses then a text based email is sent. This is all working...
1
by: farghal | last post by:
Hello as many people I'm new to ajax but trying my best to understand. At this point I got a problem I'm not able to solve. I've looked on several forums and googled internet but I can't find a...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.