Kamala - Debt Consolidation - Submit articles - Submit articles - Web Hosting

PDA

View Full Version : form validation trouble


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

ajsa52
Dec 1st 2007, 11:58 pm
Have you tried the suggestions made by hrcerqueira on your another thread about this topic: http://forums.digitalpoint.com/showpost.php?p=5450055&postcount=6 ?

derek34
Dec 2nd 2007, 5:05 pm
no I didn't notice that reply ajsa, thanks.