Note that there are some explanatory texts on larger screens.

plurals
  1. POHandling Multiple Forms on One Page
    text
    copied!<p>HTML:</p> <pre><code>&lt;form method="post" action="action=save&amp;amp;id=239" id="save-form"&gt; &lt;input type="text" value="0" name="views" /&gt; &lt;input type="submit" value="save plz" name="save" /&gt; &lt;/form&gt; &lt;form method="post" action="action=save&amp;amp;id=862" id="save-form"&gt; &lt;input type="text" value="3" name="views" /&gt; &lt;input type="submit" value="save plz" name="save" /&gt; &lt;/form&gt; &lt;form method="post" action="action=save&amp;amp;id=12" id="save-form"&gt; &lt;input type="text" value="2" name="views" /&gt; &lt;input type="submit" value="save plz" name="save" /&gt; &lt;/form&gt; </code></pre> <p>PHP:</p> <pre><code>if ($_GET["action"] == "save") { if (isset($_GET["id"]) &amp;&amp; preg_match("/^\d+$/", $_GET["id"])) { $id = $_GET["id"]; // update view count here } } </code></pre> <p>jQuery:</p> <pre><code>$('#save-form').ajaxForm({ beforeSubmit: function() { // }, success: function(data) { // } }); </code></pre> <p>I'm using this plugin: <a href="http://jquery.malsup.com/form/#html" rel="nofollow">http://jquery.malsup.com/form/#html</a></p> <p>I realize right now all of my forms share the same id <code>save-form</code>. This code works great for the first instance of <code>save-form</code>. But I want it to work for all of them. Which brings me to my main question:</p> <p>How can I modify my current jQuery/HTML to process each individual form.</p> <p>Ideally I'd have a unique id, for example <code>save-form-239</code> and <code>save-form-862</code>. But I don't want to have to write <code>$('#save-form-239')</code> and <code>$('#save-form-262');</code> for every form.. what can I do?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload