do i need to add a variable or something? D: help, please?
<html>
<head>
<script language="javascript" type="text/javascript">
function sub()
{
validateForm();
}
function validateForm()
{
if (document.forms.myForm.fname.value == "" || document.forms.myForm.fname.value == " ")
{
alert("First name must be filled out");
}
if (document.forms.myForm.lname.value == "" || document.forms.myForm.lname.value == " ")
{
alert("Last name must be filled out");
}
else
{
window.location = "ok.html";
}
}
</script>
</head>
<body>
<form name="myForm">
First name: <input type="text" name="fname">
<br>
Last name: <input type="text" name="lname">
<br>
<input type="button" value="Submit" onclick="sub()">
</form>
</body>
</html>
ok so, my code works kind of - i'm not sure how to change that 'else' statement to get it to redirect to the next page if the forms are valid.. do i need to add a variable or...?
so basically the code does what i want until you only enter the last name field then it shows the error message but it redirects still -
how do i make it so the code redirects to the success page if both of the fields are valid?
(i don't know much on javascript :/ and i know you can make it alot simplier but we HAVE to do it this way so we force the code to do it or whatever)