|
|
|
|
![]() ![]() |
Feb 26 2007, 12:55 AM
Post
#1
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 661 Joined: 31-August 06 From: Singapore Member No.: 29,189 |
I did a form, I created a checkbox under the same name 'lead_role' but I can't seem to access it in my javascript validation.
This is the code in my HTML page CODE <input name="lead_role" id="lead_role" type="checkbox" class="style30" value="1"> And this is the validation I am testing out CODE alert(document.form1.lead_role.checked); My browser returns me an 'undefined' alert message. The only way I was successful in accessing the element is using the getElementById() method but that only gets the very first instance of the checkbox. Can anyone help me out? Thanks This post has been edited by darran: Feb 26 2007, 12:55 AM |
|
|
|
Feb 26 2007, 08:20 AM
Post
#2
|
|
|
Incest is a game the whole family can play. ![]() Group: [MODERATOR] Posts: 1,216 Joined: 11-February 05 From: Heaven Member No.: 3,709 |
I made this code and tested it out in my browser, Firefox:
HTML <head></head> <body> <form name="form1"> <input name="lead_role" type="checkbox" class="style30" checked> </form> <script> if (document.form1.lead_role.checked==1) { alert(document.form1.lead_role.checked); } </script></body> I had to replace value="1" with checked because the latter worked at checking the box but the former didn't. My guesses would be:
|
|
|
|
Feb 26 2007, 10:35 AM
Post
#3
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 661 Joined: 31-August 06 From: Singapore Member No.: 29,189 |
I don't think it is a problem you are saying. This is where my javascript is located.
CODE <head><script language="javascript" type="text/javascript" src="validation.js"></script></head> This is how my form was created. CODE <form name="form1" id="form1" onsubmit="return validate();" action="register_process.asp"> Please reply me ASAP as I am rushing for time. I have attached the form as well as the javascript, hope to get a reply soon.
Attached File(s)
|
|
|
|
Feb 27 2007, 04:39 PM
Post
#4
|
|
|
Premium Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 165 Joined: 12-September 05 Member No.: 11,777 |
You can not use or it will return an error if you try to use a form element or any object that belongs to the body section of an html until it is instantiated unless you load the code on the opening <body> tag using the onload="" event.
So if you want to set the value of the checkbox do so by using the event onload="" in the <body> tag. By the way the attribute name="" is not supported by XHTML 1.0 |
|
|
|
Feb 28 2007, 01:47 AM
Post
#5
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 661 Joined: 31-August 06 From: Singapore Member No.: 29,189 |
I have found a solution to the problem, but I don't know if it was actually the solution.
I used the same name for every checkbox meaning 5 checkbox being named as lead_role or something. I name it as different seperate names, and it works perfectly fine. Thanks for all your help anyways |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 30th August 2008 - 01:57 AM |