I am using the following Javascript to populate another form based on a dynamic select using PHP/Mysql.
This works great but I also want this to trigger when I send a URL string use _GET. I've configured the select element to use this as default:
<option value="<?php echo $_GET['EmpNumber'] ?>"><?php echo $_GET['EmpFirstName'] ?> <?php echo $_GET['EmpLastName'] ?></option>
But when I call the page with values for EmpNumber,EmpFirstName and EmpLastName in the URL, the below script does not trigger. How do I achieve this as well?
<script>
      $(document).ready(function() {    
$('select').on('change', function (e) {
    var optionSelected = $("option:selected", this);
    var valueSelected = this.value;
   if(valueSelected){
           $.ajax({
            type: "POST",
            cache: false,
            url: "getinfo.php",
            data: "data="+valueSelected,
            dataType: "html",
            success: function(res) 
            {
               //alert(res);
          $('#Name').val(res + '\'s');
            },
            error: function(xhr, ajaxOptions, thrownError)
            {
            },
            async: false
        });
   }
   else {
        $('#Name').val('Value');
   }
   //alert(valueSelected);
});
});
</script>