How to check with jQuery if any form is submitted? -
i have page lot of forms, , user going pick on page. when user does, need place element somewhere else, much shopping cart really. can't seem more first form on page work intended. i've tried multiple things:
give forms same id, caused first form deed wanted, giving me info of form. give them same id again, time appending unique identifier id, of course, jquery$('#something')
doesn't grab since doesn't match. so thinking how go this. need recieve info submitted form on page. , mentioned, give them prefix of sort, have now, don't know how match it.
help appriciated!
some code requested (only illustration show mean, of course):
the html:
<form id="something-0"><input type="hidden" value="0"><input type="submit"></form> <form id="something-1"><input type="hidden" value="1"><input type="submit"></form>
the jquery:
$("#something-%").submit(function(e) { e.preventdefault(); $("#some-span").html(data); });
i want #something-% take comes after "-", hope understand.
as general answer, classify grouping of elements, utilize class
attribute, giving each element same class name. can select elements class. element can have more 1 class.
$(".something");
if must utilize id, can utilize attribute selector:
$("[id^='something']"); // elements id origin 'something' $("[id$='something']"); // elements id ending 'something'
for specific question, since want deed on form within page, simplest selection utilize element name selector:
$("form");
regardless of selector, can identify form submitted referencing this
within submit()
handler:
$("form").submit(function (e) { e.preventdefault(); var formid = this.id; // "this" reference submitted form });
jquery forms onsubmit
No comments:
Post a Comment