thomasschmidt
asked on
Determining which submit button is hit?
I have a form which submits a lot of text and images(file) to an ASP page, and it has two submit buttons on it, i do a onsubmit in the beginning form tag, like this:
<FORM ACTION="preview.asp" ENCTYPE="MULTIPART/FORM-DA TA" METHOD="POST" NAME="UPLOADFORM" OnSubmit="return CheckIT();">
here is the bottom of the form
<INPUT TYPE="SUBMIT" NAME="Action" VALUE="PREVIEW">
<INPUT TYPE="SUBMIT" NAME="Action" VALUE="ACCEPT">
here is the CheckIT function
function CheckIT(){
var LogoOK = 0;
var InsetOneOK = 0;
var InsetTwoOK = 0;
if (document.UPLOADFORM.Logo. value == "") { LogoOK = 1; }
if (document.UPLOADFORM.Inset One.value == "") { InsetOneOK = 1; }
if (document.UPLOADFORM.Inset Two.value == "") { InsetTwoOK = 1; }
if (LogoOK == 1 || InsetOneOK == 1 || InsetTwoOK) {
if(confirm("Mindst et af billedfelterne er tomme!\n\nVild du fortsætte?"))
return(true);
else
return(false);
}
else {
//document.UPLOADFORM.subm it();
return(true);
}
}
how do i determine which submit button is clicked? this function checks when both buttons are clicked, i only wan't to check when the accept button is clicked???
<FORM ACTION="preview.asp" ENCTYPE="MULTIPART/FORM-DA
here is the bottom of the form
<INPUT TYPE="SUBMIT" NAME="Action" VALUE="PREVIEW">
<INPUT TYPE="SUBMIT" NAME="Action" VALUE="ACCEPT">
here is the CheckIT function
function CheckIT(){
var LogoOK = 0;
var InsetOneOK = 0;
var InsetTwoOK = 0;
if (document.UPLOADFORM.Logo.
if (document.UPLOADFORM.Inset
if (document.UPLOADFORM.Inset
if (LogoOK == 1 || InsetOneOK == 1 || InsetTwoOK) {
if(confirm("Mindst et af billedfelterne er tomme!\n\nVild du fortsætte?"))
return(true);
else
return(false);
}
else {
//document.UPLOADFORM.subm
return(true);
}
}
how do i determine which submit button is clicked? this function checks when both buttons are clicked, i only wan't to check when the accept button is clicked???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It is a lot simpler than you think:
remove the onSubmit from the form and chaneg the buttons to
<INPUT TYPE="BUTTON" NAME="Action" VALUE="PREVIEW" ONCLICK=" CheckIT('P')">
<INPUT TYPE="BUTTON" NAME="Action" VALUE="ACCEPT" ONCLICK=" CheckIT('A')">
In the Checkit function you change
function CheckIT(){
to
function CheckIT(Which){
and you can test if (Which=='A')
You hten just change all the return true's to
document.UPLOADFORM.submit (); as it seem you were playing with
and remove the return false's
Held og lykke (Er du norsk? Vild er da uden d?)
Michel
remove the onSubmit from the form and chaneg the buttons to
<INPUT TYPE="BUTTON" NAME="Action" VALUE="PREVIEW" ONCLICK=" CheckIT('P')">
<INPUT TYPE="BUTTON" NAME="Action" VALUE="ACCEPT" ONCLICK=" CheckIT('A')">
In the Checkit function you change
function CheckIT(){
to
function CheckIT(Which){
and you can test if (Which=='A')
You hten just change all the return true's to
document.UPLOADFORM.submit
and remove the return false's
Held og lykke (Er du norsk? Vild er da uden d?)
Michel
ASKER
Problem is with that solution that i can't check in the asp script wether or not it was a preview or an accept!
i tried to submit with document.UPLOADFORM.submit ('ACCEPT') but that doesn't work. Problem with this type of form is that i can't use method=get to see what the querystring is all about!
I am from denmark, and yes there is no d in 'vil', spelling error.
i tried to submit with document.UPLOADFORM.submit
I am from denmark, and yes there is no d in 'vil', spelling error.
When I said "and you can test if (Which=='A') " I meant that you should then DO something with that information before submitting:
<FORM ACTION="preview.asp" ENCTYPE="MULTIPART/FORM-DA TA" METHOD="POST" NAME="UPLOADFORM" OnSubmit="return CheckIT(Which);">
.
.
<INPUT TYPE="HIDDEN" NAME="buttonPressed" VALUE="">
<INPUT TYPE="SUBMIT" NAME="Action" VALUE="PREVIEW">
<INPUT TYPE="SUBMIT" NAME="Action" VALUE="ACCEPT">
</FORM>
You can then do a
document.UPLOADFORM.button Pressed.va lue = Which;
before submitting. Your asp should receive
buttonPressed=A or buttonPressed=P (or buttonPressed=
if you don't put anything into the field)
Hope this helps...
Michel (Originally from Copenhagen)
<FORM ACTION="preview.asp" ENCTYPE="MULTIPART/FORM-DA
.
.
<INPUT TYPE="HIDDEN" NAME="buttonPressed" VALUE="">
<INPUT TYPE="SUBMIT" NAME="Action" VALUE="PREVIEW">
<INPUT TYPE="SUBMIT" NAME="Action" VALUE="ACCEPT">
</FORM>
You can then do a
document.UPLOADFORM.button
before submitting. Your asp should receive
buttonPressed=A or buttonPressed=P (or buttonPressed=
if you don't put anything into the field)
Hope this helps...
Michel (Originally from Copenhagen)
Sorry - the example is of course asuming my othe changes too:
<FORM ACTION="preview.asp" ENCTYPE="MULTIPART/FORM-DA TA" METHOD="POST" NAME="UPLOADFORM">
...
<INPUT TYPE="HIDDEN" NAME="buttonPressed" VALUE="">
<INPUT TYPE="BUTTON" NAME="Action" VALUE="PREVIEW" ONCLICK=" CheckIT('P')">
<INPUT TYPE="BUTTON" NAME="Action" VALUE="ACCEPT" ONCLICK=" CheckIT('A')">
</FORM>
<FORM ACTION="preview.asp" ENCTYPE="MULTIPART/FORM-DA
...
<INPUT TYPE="HIDDEN" NAME="buttonPressed" VALUE="">
<INPUT TYPE="BUTTON" NAME="Action" VALUE="PREVIEW" ONCLICK=" CheckIT('P')">
<INPUT TYPE="BUTTON" NAME="Action" VALUE="ACCEPT" ONCLICK=" CheckIT('A')">
</FORM>
ASKER