Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get the attribute action from closest form in jQuery?
    primarykey
    data
    text
    <p>I am trying to solve an issue I have where I need to grab the <code>action="/uri/"</code> from the parent form when a user clicks the submit button. If I use <code>$(form).live('submit')</code> it only works half the time. So I am using <code>$('input[type=""]').live('click')</code> instead. However as you can see in the code below, I am trying to grab the action attribute and it does not recognize it, or rather I can't seem to grab the <code>.attr('action')</code> off of it.</p> <pre><code>&lt;script&gt; var get_pages_load_options = { target: '#content', beforeSubmit: showRequest, success: showResponse }; $('input[type="submit"]').live('click',function(event){ var url = $(this).closest("form").attr('action'); var named = $(this).closest("form").attr('id') console.debug(url+"/"+named); $("#"+named).ajaxForm(get_pages_load_options); $.ajax({ type: "POST", url: url, data: {ajaxtype: "side"}, success: function(data) { $("#sidebar_menu").html(data); } }); event.preventDefault(); return false; }); &lt;/script&gt; </code></pre> <p>The html that I am trying to use looks like this (removed PHP for readability sake):</p> <pre><code>&lt;tr&gt; &lt;td class="bold" colspan="2"&gt; &lt;form id='defcon_form' name='defcon_form' action='/cityhall/' method='post'&gt; &lt;div class="left"&gt; Realm Hoarding &lt;select name='defcon_rate'&gt; &lt;option value='0'&gt;None&lt;/option&gt; &lt;option value='10'&gt;Low&lt;/option&gt; &lt;option value='20'&gt;Medium&lt;/option&gt; &lt;option value='30'&gt;High&lt;/option&gt; &lt;option value='50'&gt;Critical&lt;/option&gt; &lt;/select&gt;&lt;br /&gt; &lt;font size='-4'&gt;(Stashes Gold/Turn, Decreases Defense)&lt;/font&gt; &lt;/div&gt;&lt;div class="right"&gt; &lt;input type='submit' name='defcon' value='Update Hoarding!' /&gt; &lt;/div&gt; &lt;/form&gt; &lt;/td&gt; &lt;/tr&gt; </code></pre> <p>I know the HTML isn't the best and I will need to go back and revise it a bit. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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