0
<html>
<head>
<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
  {alert(alerttxt);return false;}
else {return true}
}
}function validate_form(thisform)
{
with (thisform)
{
if (validate_required(email,"Email must be filled out!")==false)
  {
email.focus();
return false;
if (validate_required(city,"city fill it")==false)
{
city.focus();
return false;
}
}
}
}
</script>
</head><body>
<form action="9.php"
onsubmit="return validate_form(this)"method="post">
Email: <input type="text" name="email" size="30">
city: <input type="text" name="city" size="30">
<input type="submit" value="Submit"> 
</form>
</body></html>

i used this code to generate a alert box when email box not filled correctly and it correctly generating alert box for email and not for city... ops help me in generating alert box for city also

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by aravelli
0

change the function like this ... it will work

function validate_form(thisform)
{
	with (thisform)
	{
		if (validate_required(email,"Email must be filled out!")==false)
		{
			email.focus();
			return false;
		}	
		else if (validate_required(city,"city fill it")==false)
			{
				city.focus();
				return false;
			}
		
	}
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.