Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery form plugin & programmatic submit
    text
    copied!<p>There are similar questions at SO, but none that seem to address this.</p> <p>Below is a very simplified variant of my situation. Drupal/PHP site -- I have a form w/ submit button that I am using jquery.form plugin to ajax-ly submit. It works fine if I use the submit (#submit) button. </p> <p>Now, I want to programmatically fire that button using another button (#submit2) outside of the form. I can do that using jquery click() function, but the content coming back isn't going to the ajax target as I would expect.</p> <p>I do not have much freedom to re-organize this code, else i would.</p> <p>(Note I tried to make this code easy for you to run by src-ing jquery and the form plugin from my website.)</p> <p>Ideas? Thanks!</p> <pre><code>&lt;?php if ($_REQUEST['submit'] == 'Submit') { print 'ajax returns ... ' . $_REQUEST['text']; exit; } ?&gt; &lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="http://enjoy3d.com/scripts/jquery-1.2.6.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://enjoy3d.com/scripts/jquery.form.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(function() { $('#form').ajaxForm( { target: $('#span') } ); $('#submit2').click( function() { $('#submit').click(); } ); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;span id='span'&gt;target span&lt;/span&gt; &lt;form method='post' id='form'&gt; &lt;input type='text' name='text' size='50' /&gt; &lt;input type='submit' id='submit' name='submit' value='Submit'/&gt; &lt;/form&gt; &lt;input type='submit' id='submit2' name='submit2' value='Submit Too?' /&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

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