Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Does your non-ajax version also have to be non-jQuery? If not then I also suggest (as @nnnnnn did) that you do away with the onxyz attributes and use jQuery throughout.</p> <p>As other posters have suggested, inline events are inadvisable and should be done away with.</p> <p>If your non-ajax version has to use onxyz then I'd suggest the following:</p> <p>Setup a variable that will store whether this version is to be ajax or not (how you determine this is down to you and your app context):</p> <p>var is_ajax = true;</p> <p>Then if it is an ajax version try this:</p> <pre><code>$(function(){ if(is_ajax){ //Unbind the change event from the village select box $('select[name="village"]').unbind('change'); //As an extra measure, remove the onchange attribute $('select[name="village"]').removeAttr('onchange'); //Re-bind the click event to execute your new ajax functionality $(document).on('change','select[name="village"]',function(){ //Do ajax stuff for on-change event here }); } }); </code></pre> <p>Because it sits in the document.ready function of jQuery this code should fire after the html dom (and it's associated onchange attributes) have been rendered. Therefore I'd imagine it'd effectively strip off the old event and re-bind a new one.</p> <p>Demo:</p> <p><a href="http://jsfiddle.net/foxwisp/hdL5R/" rel="nofollow">http://jsfiddle.net/foxwisp/hdL5R/</a></p> <p>If you can do away with the inline events then I imagine you'd want to do this in your initial javascript file:</p> <pre><code>$(document).on('change','select[name="village"]',function(){ document.submit_village.submit(); }); </code></pre> <p>And then the following in your ajax file to be included later:</p> <pre><code>$('select[name="village"]').removeAttr('onchange'); $(document).on('change','select[name="village"]',function(){ //Do ajax stuff here }); </code></pre> <p>As long as both are in the same scope and timeframe such that they're executed one after the other then the above should work.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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