|
|
||||

Place this code between the head tags of your webpage:
<script type="text/javascript" language="JavaScript1.2">
function Require(obForm,szFields)
{
var fields = szFields.split(",")
var szMissing= new Array();
for (x=0;x<fields.length;x++) {
if (obForm.elements[fields[x]].value.length==0) {
szMissing[szMissing.length]=new String(fields[x]);
}
}
if (szMissing.length) {
alert("The field"+((szMissing.length>1)?"s ":" ")+szMissing.join(",")+" must be filled in.");
return false
}
return true; -IE
}
</script>
Example form for your webpage:
<form action="yourscripthandler.cgi" method="post" onSubmit="return Require(this,'a,b,c')"> a <input type="text" name="a" VALUE=""><BR> b <input type="text" name="b" VALUE=""><BR> c <input type="text" name="c" VALUE=""><BR> <input type="submit"> </form>
All you need to add to an existing form to require fields are the head script, and the line
Replace a,b,c with your own field names.
You can add more fields, separated by commas. You do not have to require *all* fields for the script to work.