Solved

Determining which submit button is hit?

Posted on 1998-05-28
6
473 Views
Last Modified: 2008-02-01
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-DATA" 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.InsetOne.value == "") {      InsetOneOK = 1;      }
            if (document.UPLOADFORM.InsetTwo.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.submit();
                  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???
0
Comment
Question by:thomasschmidt
  • 3
  • 2
6 Comments
 
LVL 2

Accepted Solution

by:
anguslai earned 50 total points
ID: 1279370
Is your CheckIt() function inside the preview.asp?

if yes, you can use this simple condition check:
if(Request("orderBy")=="Accept") {
   //do whatever you like to do
}
0
 

Author Comment

by:thomasschmidt
ID: 1279371
No it's not inside the asp script, it's client side Javascript and CheckIT runs when the user submits via the <FORM ... onsubmit="CheckIT">, it doesn't submit before the criterias in checkit returns true. And it is the CheckIT function that needs to determine which button was clicked!
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1279372
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

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:thomasschmidt
ID: 1279373
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.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1279374
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-DATA" 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.buttonPressed.value = 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)
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1279375
Sorry - the example is of course asuming my othe changes too:
<FORM ACTION="preview.asp" ENCTYPE="MULTIPART/FORM-DATA" 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>
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Angular- another way of coding hide and display 3 36
Animated .jpg? 13 57
Apply tab index in forms 6 33
Master Content Pages, WebForms, and Session Variables 1 29
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now