Click to See Complete Forum and Search --> : 2 submit buttons/1 validate routine
cprice
05-21-2003, 03:22 PM
Hi all, I have a form with two submit buttons. Each needs to cause the user to go to a different web page in my app. On clicking the first submit button, I must validate the information entered by the employee and then be sent to a particular web page in the web application. If they click the second submit button, I still need to send them through the validate routine and then on to a different web page in the application.
Does any one have any good ideas on how to handle validate and two different form actions? Thanks in advance for all help!! :-)
//Add this to your code:
if(this.value=="Button One's Text"){
document.formName.action="action1.php";
} else { // if button two was clicked
document.formName.action="action2.php";
}
I could better assist you if you posted your HTML and JavaScript code.
cprice
05-21-2003, 05:26 PM
Jona, Thank you! I am definitly on the way now!! I do not know how to specify the value property for the first Submit button in the Validate routine. Thanks for your help!
function validateUSPersonalInfo(form)
{
if(this.value =="Place Data Request")
{
document.form.action="ETRDataRequests.asp";
}
else
{
document.form1.action="ETRTestRequests.asp";
}
return (
checkString(form.elements["FirstName"],sUSFirstName) &&
checkString(form.elements["LastName"],sUSLastName)&&
checkString(form.elements["RDate"],sUSReqDate) &&
checkString(form.elements["Loctn"],sLocation))
}
<form method="post" id="form1" name="form1" onSubmit="return (validateUSPersonalInfo(this.form))" >
<table>
//html code for table displaying input fields goes here
.
.
<tr>
<td><input TYPE="SUBMIT" NAME="OrderTests" VALUE="Order Test Materials"></td>
<td><input TYPE="SUBMIT" NAME="OrderData" VALUE="Place Data Request"></td>
</tr>
</table>
</form>
(Note: I colored the main parts in red that I have been struggling with.... )
function validateUSPersonalInfo(form)
{
if(form.elements[form.elements.length-1] =="Order Test Materials")
{
document.form.action="ETRTestRequests.asp";
}
else
{
document.form1.action="ETRDataRequests.asp";
}
return (
checkString(form.elements["FirstName"],sUSFirstName) &&
checkString(form.elements["LastName"],sUSLastName)&&
checkString(form.elements["RDate"],sUSReqDate) &&
checkString(form.elements["Loctn"],sLocation))
}
<form method="post" id="form1" name="form1" onSubmit="return (validateUSPersonalInfo(this.form))" >
<table>
//html code for table displaying input fields goes here
.
.
<tr>
<td><input TYPE="SUBMIT" NAME="OrderTests" VALUE="Order Test Materials"></td>
<td><input TYPE="SUBMIT" NAME="OrderData" VALUE="Place Data Request"></td>
</tr>
</table>
</form>
cprice
05-22-2003, 10:44 AM
Jona, Thank you so very much for your input! It got me to thinking! I changed the following and got each submit button to specify a different form.action as well as validate the input fields when either submit button is clicked (and only submitting the form if all required fields have something in them). Thanks again for your help!
function validateUSPersonalInfo(form)
}
return (
checkString(form.elements["FirstName"],sUSFirstName) &&
checkString(form.elements["LastName"],sUSLastName)&&
checkString(form.elements["RDate"],sUSReqDate) &&
checkString(form.elements["Loctn"],sLocation))
}
><form method="post" id="form1" name="form1" onSubmit="return (validateUSPersonalInfo(this.form))" >
<table>
//html code for table displaying input fields goes here
.
.
<tr>
<td><input TYPE="SUBMIT" NAME="OrderTests" VALUE="Order Test Materials" onClick="document.form1.action='TestReq.asp';"></td>
<td><input TYPE="SUBMIT" NAME="OrderData" VALUE="Place Data Request" onClick="document.form1.action='DataReq.asp';"></td>
</tr>
</table>
</form>:)
Well, if you do it that way... lol OK, great! Glad you got it to work.