jQuery ready() issues - $(this) not usable and code applies only to one element -



jQuery ready() issues - $(this) not usable and code applies only to one element -

im having issues getting jquery run when dom ready.

i have 2 forms, each <select> when code runs should load in other form elements.

when user first loads page, want these selects on ready() grab attributes (form action, load() target etc) , load in. works fine when using change() , can 1 <select> work when not both.

html class="lang-html prettyprint-override"><form action="php/bagcreate/newbag_bag.php" method="post" id="form1"> <select id="target" data-target="upform" class="get" name="baglevel"> <option>1</option> <option>2</option> <option>3</option> </select> </form> <form action="php/bagcreate/storeitems_bag.php" method="post" id="form2"> <select id="target2" data-target="upformtype" class="get" name="itemname"> <option>a</option> <option>b</option> <option>c</option> </select> </form> js

this works single form, sec wont load

class="lang-js prettyprint-override">$(document).ready(function(){ $('select.get').ready(function() { var action = $('select.get').parent().attr('action'); var target = $('select.get').data('target'); $('#'+target).load(action, $('select.get').parent().serializearray()); });

changing select.get this within ready function causes neither of forms load.

using change() works fine both forms, although bit of repetition

class="lang-js prettyprint-override">$('select.get').change(function() { var action = $(this).parent().attr('action'); var target = $(this).data('target'); $('#'+target).load(action, $(this).parent().serializearray()); });

just trigger alter event on pageload ?

$('select.get').change(function() { var action = $(this).parent().attr('action'); var target = $(this).data('target'); $('#'+target).load(action, $(this).parent().serializearray()); }).change(); //trigger on pageload ...

jquery document-ready

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

Hibernate criteria by a list of natural ids -

ios - Lagging ScrollView with UIWebview inside -