Posted on July 2, 2009 - by Dr. Div
Simple Javascript Alert for a Required Field
Here is a simple way of checking for existence of any value in a specific form field:
Insert this code insisde the head tag on your page:
<script type="text/javascript">
function checkField(){
if (document.myForm.myField.value == ""){
alert ("Please Insert Field");
return false;
}
else{
document.myForm.submit();
}
}
</script>
Insert this code inside the body tag on your page:
<body>
<form action="http://www.drdiv.com" method="post" name="myForm" onSubmit="return checkField();">
<input name="myField" type="text" value=""/>
<input name="" type="submit" value="send"/>
</form>
</body>
