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

Recommended Answers

All 3 Replies

post your appropriate code....

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>

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>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.