CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> GotoCode Archive

 Validate entry of mandaotory fileds

Print topic Send  topic

Author Message
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)">

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.