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.
<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
$('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
Post a Comment