Im having issues with getting some jQuery to run when the DOM is ready.
I have two forms, each with a <select> which when my code runs should load in other form elements.
When the user first loads the page, I want these selects on ready() to grab certain attributes (form action, load() target etc) and then load that in. Works perfectly fine when using change() and I can get one <select> to work when but not both.
HTML
<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 for a single form, but the second wont load
$(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 to this inside the ready function causes neither of the forms to load.
Using change() works perfectly fine for both forms, although it is a bit of a repetition
$('select.get').change(function() {
var action = $(this).parent().attr('action');
var target = $(this).data('target');
$('#'+target).load(action, $(this).parent().serializeArray());
});
Just trigger the change event on pageload ?