Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onSubmit with validation still submits

Status
Not open for further replies.

Kaos2800

Programmer
Jan 16, 2001
17
US
I'm trying to create a fake password screen. But I don't want them to be able to access the next page unless the correct password is entered. When I run the page, and don't enter a password then the alert pops up like it should, but it then goes to the next page anyway. Any and all help would be great, thanks.


function valid(form)
{
if (form.code.value == "")
{
alert("Please enter a password.")
return false;
}

else if (form.code.value != "david")
{
alert("Incorrect password entered.")
return false;
}

else if (form.code.value == "david")
{
alert("Correct password entered.")
return true;
}
}


<form Action=&quot;Main.html&quot; method=&quot;post&quot; onSubmit=&quot;valid(this);&quot;>

 
Try this :

function valid(form)
{
if (form.code.value == &quot;&quot;)
{
alert(&quot;Please enter a password.&quot;)
return false;
}

else if (form.code.value != &quot;david&quot;)
{
alert(&quot;Incorrect password entered.&quot;)
return false;
}

//else if (form.code.value == &quot;david&quot;)
//{
//alert(&quot;Correct password entered.&quot;)
//return true;
//}
return true;
}


<form Action=&quot;Main.html&quot; method=&quot;post&quot; onSubmit=&quot;return valid(this);&quot;> Regards

Big Bad Dave

davidbyng@hotmail.com
 
Thanks, I knew that was it the second I saw it. And it works. Thanks again!

-David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top