0

I have a few forms with the IDs comment_addXXX. I want to submit all of these at once, rather than individually submit each form.

i.e. Can I simplify something like:

$('#comment_add1111').submit();
$('#comment_add111122').submit();
$('#comment_add1222111').submit();
$('#comment_add11133331').submit();

Into something like:

$('#comment_add*').submit();
Kranu
2,56516 silver badges22 bronze badges
asked Feb 2, 2011 at 12:04
0

3 Answers 3

3

Try the starts with selector

$('form[id^=comment_add]').each(function() {
 $(this).submit();
});

See http://api.jquery.com/attribute-starts-with-selector/

answered Feb 2, 2011 at 12:09
Sign up to request clarification or add additional context in comments.

Comments

0

or example, consider the HTML: Example :

<form id="target" action="destination.html">
 <input type="text" value="Hello there" />
 <input type="submit" value="Go" />
</form>
<div id="other">
 Trigger the handler
</div>

The event handler can be bound to the form:

$('#target').submit(function() {
 alert('Handler for .submit() called.');
 return false;
});

other the id of a control:

$('#other').click(function() {
 $('#target').submit();
});
answered Feb 2, 2011 at 12:07

Comments

0

Aren't quotation marks necessary, Petah?

$('form[id^="comment_add"]').each(function() {
 $(this).submit();
});
answered Feb 2, 2011 at 12:30

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.