![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hello there: I've been trying to create two different sets of required fields in one form and to use a radiobutton as sort of a switcher between these sets. In my HTML form there are two radiobuttons with values 'Via Email' and 'Printed Brochure'. If a user checks 'Via Email' radiobutton, he/she has to fill out Email and Name fields only, if it's radiobutton 'Printed Brochure' is checked, a user has to fill Email, Name and ALSO Address field. I use this script below, but it doesn't seem to work, and I can't get it why.... I'd appreciate it if somebody would help me with this. script type="text/javascript" function validate() { x=document.myForm varCheckedButton=x.receiveVia.value varName=x.Name.value varEmail=x.Email.value varAddress=x.Address.value if (varCheckedButton==byEmail) { if (varEmail==-1) { alert("Please fill in Email") submitOK="False" } if (varName.length==0) { alert("You must enter your Name") submitOK="False" } if (submitOK=="False") { return false } } else { if (varCheckedButton==printed) { if (varEmail==-1) { alert("Please fill in Email") submitOK="False" } if (varName.length==0) { alert("You must enter your Name") submitOK="False" } if (varAddress.length==0) { alert("You must enter your Address") submitOK="False" } } } } /script form name="myForm" action="" method="POST" enctype="x-www-form-urlencoded" p><input type="radio" name="receiveVia" value="printed"> Printed brochure</p p><input type="radio" name="receiveVia" value="byEmail"> Via Email</p p><input type="image" src="submit.gif" border="0" value="Submit" width="75" height="17" ALT="Submit button" onClick="validate();"></p /form Thanks in advance. Oleg |
#3
| |||
| |||
|
|
Hello there: I've been trying to create two different sets of required fields in one form and to use a radiobutton as sort of a switcher between these sets. In my HTML form there are two radiobuttons with values 'Via Email' and 'Printed Brochure'. If a user checks 'Via Email' radiobutton, he/she has to fill out Email and Name fields only, if it's radiobutton 'Printed Brochure' is checked, a user has to fill Email, Name and ALSO Address field. I use this script below, but it doesn't seem to work, and I can't get it why.... I'd appreciate it if somebody would help me with this. Heya Oleg, |
#4
| |||
| |||
|
#5
| |||
| |||
|
|
As by Shawn's reply, you should also fix the form access with an id attribute, and "var x = document.getElementById("myForm")". |
#6
| |||
| |||
|
|
I disagree. Use a name attribute, use the forms collection: document.forms['formName'].elements['elementName'].property is more widely supported, backwards compatible. |

#7
| |||
| |||
|
|
Randy Webb wrote: I disagree. Use a name attribute, use the forms collection: document.forms['formName'].elements['elementName'].property is more widely supported, backwards compatible. That depends on whether the client needs compatibility back to NN4. ![]() XHTML doesn't support forms with name attributes, |
|
but luckily will ignore unknown attributes and their values. |
#8
| |||
| |||
|
|
The forms and elements collections can look up elements by ordinal, name, and id. In fact, if the argument is a string, ids are checked before names. Backward compatibility is irrelevant. The possibility remains that control access through the collections will be faster than by a gEBI call. The content of the collections could be implemented so that it is actually an array[1] containing only forms, and form controls, respectively[2]. If this is the case, it will be much quicker to index it than to search the entire document tree for an id. Heya Michael, |

|
XHTML will ignore unknown attributes? I thought that an unknown attribute would cause the markup to be invalid (it is in HTML), which would cause a conforming browser to immediately halt parsing the document. |
#9
| |||
| |||
|
|
Michael Winter wrote: |
|
The possibility remains that control access through the collections will be faster than by a gEBI call. The content of the collections could be implemented so that it is actually an array[1] containing only forms, and form controls, respectively[2]. If this is the case, it will be much quicker to index it than to search the entire document tree for an id. Thanks. Good to know these details. ![]() |
|
XHTML will ignore unknown attributes? I thought that an unknown attribute would cause the markup to be invalid (it is in HTML), which would cause a conforming browser to immediately halt parsing the document. Unknown attributes and elements are free to be written into XHTML documents for forward compatibility. See http://www.w3.org/TR/2001/REC-xhtml-...orm_user_agent . |
#10
| |||
| |||
|
|
Hello there: I've been trying to create two different sets of required fields in one form and to use a radiobutton as sort of a switcher between these sets. In my HTML form there are two radiobuttons with values 'Via Email' and 'Printed Brochure'. If a user checks 'Via Email' radiobutton, he/she has to fill out Email and Name fields only, if it's radiobutton 'Printed Brochure' is checked, a user has to fill Email, Name and ALSO Address field. I use this script below, but it doesn't seem to work, and I can't get it why.... I'd appreciate it if somebody would help me with this. script type="text/javascript" function validate() { x=document.myForm varCheckedButton=x.receiveVia.value varName=x.Name.value varEmail=x.Email.value varAddress=x.Address.value if (varCheckedButton==byEmail) { if (varEmail==-1) { alert("Please fill in Email") submitOK="False" } if (varName.length==0) { alert("You must enter your Name") submitOK="False" } if (submitOK=="False") { return false } } else { if (varCheckedButton==printed) { if (varEmail==-1) { alert("Please fill in Email") submitOK="False" } if (varName.length==0) { alert("You must enter your Name") submitOK="False" } if (varAddress.length==0) { alert("You must enter your Address") submitOK="False" } } } } /script form name="myForm" action="" method="POST" enctype="x-www-form-urlencoded" p><input type="radio" name="receiveVia" value="printed"> Printed brochure</p p><input type="radio" name="receiveVia" value="byEmail"> Via Email</p p><input type="image" src="submit.gif" border="0" value="Submit" width="75" height="17" ALT="Submit button" onClick="validate();"></p /form Thanks in advance. Oleg |
![]() |
| Thread Tools | |
| Display Modes | |
| |