Link to home
Start Free TrialLog in
Avatar of wrynn
wrynn

asked on

onsubmit validation with js not working in firefox

im trying to use javascript to validate a form using onsubmit, but firefox is ignoring the javascript and not blocking the submission (it works fine in ie6), the code is below:



function checkscript(form1) {

if(document.forms.form1.first_name.value=="")
{
alert("Please enter your first name.");
return false;
}

if(document.forms.form1.last_name.value=="")
{
alert("Please enter your last name.");
return false;
}

if(document.forms.form1.username.value=="")
{
alert("Please enter your username.");
return false;
}

return true;

}

<form name="form1" id="form1" method="post" onsubmit="return checkscript()" action="process.php">

Avatar of Xxavier
Xxavier
Flag of Canada image

Hi wrynn!! Its Xxavier here!! :0)  

Probably should be

document.form1.first_name.value==""

not

document.forms.form1.first_name.value==""

Ta Da!!

Xxavier :0)
ASKER CERTIFIED SOLUTION
Avatar of Xxavier
Xxavier
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wrynn
wrynn

ASKER

thanks guys.  didnt realize i was passing the form object and not even using it!  also i deleted the extra "form" before .form1.field.value

i guess maybe i was using the wrong <script> tag too