0

Hi, I'm new to Javascript and I'm having trouble with my function to check for missing information in the code. Any ideas? Thanks

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by essential
0

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(first name,"Missing Information!")==false)
{first name.focus();return false;}
}
}


<form action="submitpage.htm"
onsumbit="return validate_form(this)"
method="post">
</form>

0

Lets head back to the basic! Hope this 1 wil help you! Good day!

<html>
<head>
<title><!--Sample--></title>
<script type="text/javascript">
<!--
function validate( form )
{ var nameField = form.firstname;
  if ( nameField.value == "" ) { alert('\nMissing Information!'); nameField.focus(); return false; }
else { alert('\nDo the next stuff!'); return true;
 }
}
//-->
</script>
</head>
<body>
<form action="submitpage.htm" name="form1" onsubmit="return validate( this );" method="post">
<input type="text" name="firstname" size="20" value="" /><br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
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.