On Nov 7, 2:02 pm, Oleg Konovalov <okono...@verizon.netwrote:
RobG wrote:
On Nov 7, 2:50 pm, Oleg Konovalov <okono...@verizon.netwrote:
Hi,
I am working on Struts/HTML/Javascript application.
Have 2 buttons on the page, Save and Cancel,
both are supposed to bring me to the same page,
but Save also performs validation, and Cancel - should not.
Both buttons are of Submit type and have same name ("SubmitValue"), e.g.:
<input type="submit" id="SaveBtn" name="submitValue" value="Save">
So how do I distinguish which button was clicked on Submit for the form:
Change either the name or value of one of the buttons so your server
can tell which one was clicked.
--
Rob
Values arre different, one is "Save", other one is "Cancel"
How do I get it there:
<form name="input" onClick="if (??? = "SaveBtn") return validate()" ?
You got it completely wrong. First of all, you don't put <form
onclick..but <input type="submit" onclick...>. Here's a short
example (untested) how you should go:
<script type="text/javascript">
function save()
{
// check everything
if ( everythingOk )
return true;
return false;
}
function cancel()
{
return true;
}
</script>
<form action="...">
<input type="submit" value="Save" name="save" onclick="return
save()" />
<input type="submit" value="Cancel" name="cancel" />
</form>
If you don't need any validation on cancel, then just don't handle it
in javascript,
but let it be a normal submit button. save(), however, should do the
validation, and if it
returns false, then submitting won't happen. If it returns true, it
will.
Now, what I really don't understand - why did you put both buttons
have the same name? If you let
them have the same name, then the server-side script won't be able to
know what button was pressed.
Having them have different names, like above, the server-side script
will be able to distinguish which
button was pressed and act accordingly.