jmccann
|
| Posted: 10/17/2002, 6:59 AM |
|
I wish to check for the input of two mandatory fileds on an Insert Form. I understand CC wil check for mandatory field at the server. How can I check for field entries at the client side using Javascript?
|
|
|
 |
cornwell
|
| Posted: 10/17/2002, 2:21 PM |
|
This to the header of the html page.
The required field names will need some consistency of naming
<script language="JavaScript">
function check_form(form)
{
return_boolean = true
show_err = false
obj = eval(form)
for(i=0;i<obj.length;i++)
{
field_name = obj.elements.name;
// The next line assumes all 'required' fields have an _rq suffix.
if (field_name.indexOf("_rq") != -1) {
if (obj.elements.value == "")
{
obj.elements.style.backgroundColor = "#FFFFCC";
show_err = true
return_boolean = false
}
else
{
obj.elements.style.backgroundColor = "white";
}
}
}
if (show_err == true) {
alert("Not all required fields provided");
}
else {
alert("Record saved");
}
return return_boolean;
}
</script>
Then in the form on the HTML page put the onsubmit call.
<form name="myname" onsubmit="return check_form(this)">
|
|
|
 |
|