O
Oleg
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
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