Below is my code snippet:
setTimeout(function(){
var backed = localStorage.getItem("backed");
if(backed == "goback"){
var order = $("#plan").val();
<?php if(isset($_GET['frm'])){ ?>
$('select[id="type"] option:eq(0)').prop('selected',1);
$('select[id="plan"] option:eq(0)').prop('selected',1);
<?php
$name = $_GET['name'];
$update = $_GET['data'];
$type = $_GET['type'];
?>
// Filter One
$('select[id="data"] option:eq(0)').prop('selected',<?= $update ?>);
$('select[id="type"] option:eq(0)').prop('selected',<?= $type ?>);
$('select[id="plan"] option:eq(0)').find('option[value="'+order+'"]').attr('selected','selected').trigger('change');
<?php
} else { ?>
// Render with saved history
$('select[id="plan"] option:eq(0)').find('option[value="'+order+'"]').attr('selected','selected').trigger('change');
<?php
}
?>
}
}, 3000);
I designed this logic to pull values from a GET string and populate a JS function. Once done, using jQuery to populate a form with those values and then trigger a drop down selection; which on the front-end triggers a rendering of a data table with those pre-populated form values.
It worked for the most part, with one exception. If the value I'm pre-populating, matches the value that's already there in the drop down, the trigger('change') doesn't take.
To combat that, I thought to set default values (You'll see after the IF statement), and then triggering the change after the values are set.
I also attempted populating the form and manually callingthe function that runs on change. This didn't work either.
The above approach isn't my preference as I'd much rather work with the controller and that performs the original data pull; but modifying that process isn't an option for me at the moment. So I'm limited to the front-end fix. Can anyone advise on the best approach to get the trigger firing after the default is set?
Thanks in advance.