darran 0 Report post Posted February 26, 2007 (edited) 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 <input name="lead_role" id="lead_role" type="checkbox" class="style30" value="1"> And this is the validation I am testing outalert(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 Edited February 26, 2007 by darran (see edit history) Share this post Link to post Share on other sites
electriic ink 1 Report post Posted February 26, 2007 I made this code and tested it out in my browser, Firefox: <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: You tried to refer to an object that hadn't been already set (put the javascript after the html). You didn't put the <form name="form1"> bit in your code, so when it looked for an object whose name was form1 it couldn't find it.Anyway, if that doesn't solve the problem, it helps if you post the entire page of code that you are using. Share this post Link to post Share on other sites
darran 0 Report post Posted February 26, 2007 I don't think it is a problem you are saying. This is where my javascript is located. <head><script language="javascript" type="text/javascript" src="validation.js"></script></head> This is how my form was created.<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.form.txt js.txt Share this post Link to post Share on other sites
saga 0 Report post Posted February 27, 2007 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 Share this post Link to post Share on other sites
darran 0 Report post Posted February 28, 2007 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 Share this post Link to post Share on other sites