...

View Full Version : IF statements



npala2001
12-12-2006, 06:23 PM
I am trying to find how to do the following:

if Field 1 is completed

then

Field 2 must be filled out.

I remember an online site that showed me, but I cant find it.

martin_narg
12-13-2006, 12:14 PM
Example:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Form validation</title>
<script type="text/javascript" language="javascript">
function validate() {
var theForm = document.myForm;

if(theForm.theFirstField.value.length > 1 && theForm.theSecondField.value.length == 0) {
alert("Please fill in the second field");
return false;
}

alert("The form is ok to submit.");
return true;
}
</script>
</head>

<body>
<form name="myForm" method="post" action="?" onsubmit="return validate();">

<p>First field:<br /><input type="text" name="theFirstField" /></p>
<p>Second field:<br /><input type="text" name="theSecondField" /></p>

<input type="submit" name="theSubmit" value="Submit" />
</form>
</body>
</html>Hope this helps.

m_n

npala2001
12-13-2006, 06:17 PM
Awesome Thank you!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum