I am trying to validate a form using javascript. The form has two submit buttons. If the first button is clicked, the form should run a brief verification, then change the form action to an asp page. If the second button is clicked, the for will run the verification, then change the form action to a different page. The verification is simply to verify that the field is not empty.
What happens now is that if you try to submit the form with either button, an alert box appears, then when you clear that alert box, another alert box appears. Finally, when you click either submit button, both buttons take you to the first action page.
Below is the code I am trying to use. It is almost like the if else portion is not functioning.
Any suggestions would be great! Thanks!
<SCRIPT LANGUAGE="JavaScript">
<!--
// this script is used to change the action of the form
// dependent on which button you select
function checkform ( form )
{
if ((document.office.BranchCode.value != ""
&& (document.office.S1.value == "Create New Entry"
) {
document.office.action = "itemlist.asp";
return true;
}
else if ((document.office.BranchCode.value != ""
&& (document.office.S2.value == "Modify Existing Records"
) {
document.office.action = "itemmodify.asp";
return true;
}
else {
alert( "Please Select an Item." );
document.office.BranchCode.focus();
return false ;
}
}
//-->
</SCRIPT>
What happens now is that if you try to submit the form with either button, an alert box appears, then when you clear that alert box, another alert box appears. Finally, when you click either submit button, both buttons take you to the first action page.
Below is the code I am trying to use. It is almost like the if else portion is not functioning.
Any suggestions would be great! Thanks!
<SCRIPT LANGUAGE="JavaScript">
<!--
// this script is used to change the action of the form
// dependent on which button you select
function checkform ( form )
{
if ((document.office.BranchCode.value != ""
document.office.action = "itemlist.asp";
return true;
}
else if ((document.office.BranchCode.value != ""
document.office.action = "itemmodify.asp";
return true;
}
else {
alert( "Please Select an Item." );
document.office.BranchCode.focus();
return false ;
}
}
//-->
</SCRIPT>