pwinters
Programmer
- Sep 12, 2002
- 34
Hi,
I am trying to validate a form when the user hits the submit button. Currently, when a field is left blank, an error message pops up to instruct the user to enter something in the blank field, but when you click Ok on the error message, it processes the submit (which processes a query). I want the user to be able to go back and update the field before the query is processed. Can anyone help me with this?
Here is my validation code...
<script language="JavaScript">
<!-- hide this script from non-javascript-enabled browsers
function validateData()
{
var AddProjForm = new Object();
AddProjForm = document.addproj;
if (txtCheckPrintable(AddProjForm.initnum, true, "Initiative Number Missing. Error: "
&&
txtCheckPrintable(AddProjForm.projname, true, "Project Name Missing. Error: "
)
{
if (AddProjForm.relmonth.options[AddProjForm.relmonth.selectedIndex].value == ""
{
alert("Must select a Release"
;
AddProjForm.relmonth.focus();
return false;
}
{
if (AddProjForm.primstatus.options[AddProjForm.primstatus.selectedIndex].value == ""
{
alert("Must select a Primary Status"
;
AddProjForm.primstatus.focus();
return false;
}
{
if (AddProjForm.projstage.options[AddProjForm.projstage.selectedIndex].value == ""
{
alert("Must select a Project Stage"
;
AddProjForm.projstage.focus();
return false;
}
{
if (AddProjForm.spmid.options[AddProjForm.spmid.selectedIndex].value == ""
{
alert("Must select a SPM ID"
;
AddProjForm.spmid.focus();
return false;
}
{
if (AddProjForm.spin.options[AddProjForm.spin.selectedIndex].value == ""
{
alert("Must select a Filespin Option"
;
AddProjForm.spin.focus();
return false;
}
{
if (AddProjForm.adjstatus.options[AddProjForm.adjstatus.selectedIndex].value == ""
{
alert("Must select an Adjustment Status"
;
AddProjForm.adjstatus.focus();
return false;
}
}
}
}
}
}
}
return true;
{
return false;
}
}
// -->
</script>
And this is in my form:
<form method="post" name="addproj" action="../handlers/addproj_hdlr.jsp" onSubmit="return validateData();">
THANKS
I am trying to validate a form when the user hits the submit button. Currently, when a field is left blank, an error message pops up to instruct the user to enter something in the blank field, but when you click Ok on the error message, it processes the submit (which processes a query). I want the user to be able to go back and update the field before the query is processed. Can anyone help me with this?
Here is my validation code...
<script language="JavaScript">
<!-- hide this script from non-javascript-enabled browsers
function validateData()
{
var AddProjForm = new Object();
AddProjForm = document.addproj;
if (txtCheckPrintable(AddProjForm.initnum, true, "Initiative Number Missing. Error: "
txtCheckPrintable(AddProjForm.projname, true, "Project Name Missing. Error: "
{
if (AddProjForm.relmonth.options[AddProjForm.relmonth.selectedIndex].value == ""
{
alert("Must select a Release"
AddProjForm.relmonth.focus();
return false;
}
{
if (AddProjForm.primstatus.options[AddProjForm.primstatus.selectedIndex].value == ""
{
alert("Must select a Primary Status"
AddProjForm.primstatus.focus();
return false;
}
{
if (AddProjForm.projstage.options[AddProjForm.projstage.selectedIndex].value == ""
{
alert("Must select a Project Stage"
AddProjForm.projstage.focus();
return false;
}
{
if (AddProjForm.spmid.options[AddProjForm.spmid.selectedIndex].value == ""
{
alert("Must select a SPM ID"
AddProjForm.spmid.focus();
return false;
}
{
if (AddProjForm.spin.options[AddProjForm.spin.selectedIndex].value == ""
{
alert("Must select a Filespin Option"
AddProjForm.spin.focus();
return false;
}
{
if (AddProjForm.adjstatus.options[AddProjForm.adjstatus.selectedIndex].value == ""
{
alert("Must select an Adjustment Status"
AddProjForm.adjstatus.focus();
return false;
}
}
}
}
}
}
}
return true;
{
return false;
}
}
// -->
</script>
And this is in my form:
<form method="post" name="addproj" action="../handlers/addproj_hdlr.jsp" onSubmit="return validateData();">
THANKS