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.myFo rm
varCheckedButto n=x.receiveVia. value
varName=x.Name. value
varEmail=x.Emai l.value
varAddress=x.Ad dress.value
if (varCheckedButt on==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=="Fal se")
{
return false
}
}
else
{
if (varCheckedButt on==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.len gth==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="receiveVi a" value="printed" > Printe d
brochure</p>
<p><input type="radio" name="receiveVi a" value="byEmail" > Via
Email</p>
<p><input type="image" src="submit.gif " border="0" value="Submit"
width="75" height="17"
ALT="Submit button" onClick="valida te();"></p>
</form>
Thanks in advance.
Oleg
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.myFo rm
varCheckedButto n=x.receiveVia. value
varName=x.Name. value
varEmail=x.Emai l.value
varAddress=x.Ad dress.value
if (varCheckedButt on==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=="Fal se")
{
return false
}
}
else
{
if (varCheckedButt on==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.len gth==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="receiveVi a" value="printed" > Printe d
brochure</p>
<p><input type="radio" name="receiveVi a" value="byEmail" > Via
Email</p>
<p><input type="image" src="submit.gif " border="0" value="Submit"
width="75" height="17"
ALT="Submit button" onClick="valida te();"></p>
</form>
Thanks in advance.
Oleg
Comment