I am clicking a submit button using this:
$('input[type=submit]').click();
The problem is that I have more that 1 submit button on my page so I need to target a specific submit button.
How could I do that?
I am clicking a submit button using this:
$('input[type=submit]').click();
The problem is that I have more that 1 submit button on my page so I need to target a specific submit button.
How could I do that?
Way late to the party, but if your submit buttons have names:
One other suggestion!
I had a form with multiple submits, that also had varying value attributes, so I couldn't simply submit the form after I performed my built in confirmation.
Instead, I added a few hidden buttons that I forced a click on after I got a Yes back from my confirmation.
Here are the buttons:
And here's the jQuery:
hmm it cant work with a wizard form with this intacted
If you add a marker, like a specific id or class to your
input
, you can make your selector more specific. For example, if you give the button you want the ID ofform-btn
like this:You can select it like this:
Or just:
Add
id
s to each button and select theid
with jQuery.Or, if the forms have
id
s, then just target the form and submit it like so:If you know the number of
submit
inputs and which one (in order) you want to trigger aclick
on then you can usenth-child()
syntax to target it. Or add an ID or a class to each one that separates them from the other.Selecting the elements by their index:
There are actually several ways to do this including using
.eq()
: http://api.jquery.com/eqSelecting the elements by their id:
Note that
.click()
is short for.trigger('click')
.