0

I'm trying to figure out (on the client side) how to use javascript to submit a specific submit button for a form with multiple submit buttons.

Currently,

            document.forms[0].submit() 

does not seem to be working because it submits the first submit button instead of the second one, which is what I want to be submitted.

Is there a way to submit only the second submit button?

Here is an example of the buttons:

            <input type="submit" class="submitButton_1" id="cancelButton" value="Cancel"
               title="Cancel" name="cancel"/>

            <input type="submit" class="submitButton_2 "  id="Button" value="Test"
                   title="Test" name="TestButton"/>
4
  • What do you mean by "submitting a button"? Commented Oct 17, 2014 at 2:39
  • What's that "Cancel" supposed to do? Could you replace it with a "Reset"? Ex.: <input type="reset" class="submitButton_1" id="cancelButton" value="Cancel" title="Cancel" name="cancel"/> Commented Oct 17, 2014 at 2:55
  • @chipChocolate.py—that will submit the second form, the OP wants to submit the first form but with the second submit button. Commented Oct 17, 2014 at 3:06
  • Call the second button's click method: document.forms[0].TestButton.click(). Commented Oct 17, 2014 at 3:07

1 Answer 1

2
document.getElementById('whatever-id-here').click();

will "click" on the button with ID whatever-id-here

Sign up to request clarification or add additional context in comments.

1 Comment

More appropriate for the OP is likely document.forms[0].cancel.click() or document.forms[0].TestButton.click().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.