derek34
Dec 1st 2007, 11:18 pm
Hi I'm trying to validate a form but I'm having problems validating the radio buttons and the select menu (or options menu).
Here's the code I tried:
<script language="javascript" type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{alert(alerttxt);return false;}
else {return true}
}
}
function validate_radio(radio,alerttext){
with (radio)
{
if (!radio.checked){
alert(alerttext);return false;}
else {return true;}
}
}
function validate_dropdown(drop,alerttext){
with(drop){
if (value=="Please Choose..."){alert(alerttext);return false;}
else {return true;}
}
}
function validate_form(thisform)
{
with (thisform)
{
if (validate_required(screen,"Screenname must be filled out!")==false)
{screen.focus();return false;}
if (validate_required(first,"You must have a first name.")==false)
{first.focus();return false;}
if (validate_required(last,"you must have a last name.")==false)
{last.focus();return false;}
if (validate_required(age,"How old are you?")==false)
{age.focus();return false;}
if (validate_required(occupation,"Please provide a school or occupation")==false)
{occupation.focus();return false;}
if (validate_required(email,"Email must be filled out!")==false)
{email.focus();return false;}
if (validate_required(phone,"Please Provide a phone number.")==false)
{phone.focus();return false;}
if (validate_radio(rent,"Are you renting a computer?")==false)
{rent.focus();return false;}
if (validate_radio(pizza,"Please Choose a type of pizza")==false)
{pizza.focus();return false;}
if (validate_dropdown(city,"Please choose a city")==false)
{pizza.focus();return false;}
}
}
</script>
Any idea why the radio buttons and the option menu validation isn't working?
Much appreciated.
- Derek
Here's the code I tried:
<script language="javascript" type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{alert(alerttxt);return false;}
else {return true}
}
}
function validate_radio(radio,alerttext){
with (radio)
{
if (!radio.checked){
alert(alerttext);return false;}
else {return true;}
}
}
function validate_dropdown(drop,alerttext){
with(drop){
if (value=="Please Choose..."){alert(alerttext);return false;}
else {return true;}
}
}
function validate_form(thisform)
{
with (thisform)
{
if (validate_required(screen,"Screenname must be filled out!")==false)
{screen.focus();return false;}
if (validate_required(first,"You must have a first name.")==false)
{first.focus();return false;}
if (validate_required(last,"you must have a last name.")==false)
{last.focus();return false;}
if (validate_required(age,"How old are you?")==false)
{age.focus();return false;}
if (validate_required(occupation,"Please provide a school or occupation")==false)
{occupation.focus();return false;}
if (validate_required(email,"Email must be filled out!")==false)
{email.focus();return false;}
if (validate_required(phone,"Please Provide a phone number.")==false)
{phone.focus();return false;}
if (validate_radio(rent,"Are you renting a computer?")==false)
{rent.focus();return false;}
if (validate_radio(pizza,"Please Choose a type of pizza")==false)
{pizza.focus();return false;}
if (validate_dropdown(city,"Please choose a city")==false)
{pizza.focus();return false;}
}
}
</script>
Any idea why the radio buttons and the option menu validation isn't working?
Much appreciated.
- Derek