mw2005
08-28-2005, 07:47 PM
Hi all;
In my form code it will validate to see if the name and email address contains some information. But for example if i click submit without entering any information in the input fields only the name error appears and not the other one also if there was an error in the name and it was corrected it will not go. I cannot figure out what is the problem.
Thanks in Advance,
MW2005
<script type="text/javascript">
function validate(f) {
if(f.name.value == "" ) {
document.getElementById('first').innerHTML='Invalid Input';
return (false);}
if(f.email.value.indexOf( "@" ) == -1) {
document.getElementById('address').innerHTML='Invalid Input';
return (false);}
alert( "IT WORKS!" );
return (false);}
//change to return true and delete alert
</script>
<form method="post" name="myForm" onsubmit="return validate(this)">
<label for="name">First Name</label>
<input type="text" name = "name" value=""/><span id="first"></span>
<br />
<label for="email">Email Address:</label>
<input type="text" name="email" value="" onChange="javascript:this.value=this.value.toLowerCase();"/><span id="address"></span>
<br />
<label for="query">Message</label>
<textarea name="query"></textarea>
<br />
<input type="submit" value="Submit" id="submitbutton"/>
<input type="reset" value="Reset" id="Resetbutton">
</form>
</body>
</html>
In my form code it will validate to see if the name and email address contains some information. But for example if i click submit without entering any information in the input fields only the name error appears and not the other one also if there was an error in the name and it was corrected it will not go. I cannot figure out what is the problem.
Thanks in Advance,
MW2005
<script type="text/javascript">
function validate(f) {
if(f.name.value == "" ) {
document.getElementById('first').innerHTML='Invalid Input';
return (false);}
if(f.email.value.indexOf( "@" ) == -1) {
document.getElementById('address').innerHTML='Invalid Input';
return (false);}
alert( "IT WORKS!" );
return (false);}
//change to return true and delete alert
</script>
<form method="post" name="myForm" onsubmit="return validate(this)">
<label for="name">First Name</label>
<input type="text" name = "name" value=""/><span id="first"></span>
<br />
<label for="email">Email Address:</label>
<input type="text" name="email" value="" onChange="javascript:this.value=this.value.toLowerCase();"/><span id="address"></span>
<br />
<label for="query">Message</label>
<textarea name="query"></textarea>
<br />
<input type="submit" value="Submit" id="submitbutton"/>
<input type="reset" value="Reset" id="Resetbutton">
</form>
</body>
</html>