What I am doing is passing data via Ajax and putting that data into a Dropdown. So when the data gets passed it should match the selected value in the dropdown and then appear on top with SELECTED on the option so we can see the data right away. So if the data being returned is Product2 then Product2 should be SELECTED and visable.
<script type="text/javascript">
function myFunction() {
var skuvalue=document.my_form.modlistbox.value;
$.ajax({ url: 'modify.php',
data: {sku: skuvalue},
type: 'post',
dataType: "html",
error: function (request, error) {
console.log(arguments);
alert("ERROR: " + error);
},
success: function(data) {
var jsonvalue = $.parseJSON(data);
console.log(jsonvalue);
$(document).ready;
$("#modsku").val(jsonvalue[0]);
$("#modproduct").val(jsonvalue[1]).prop('selected', true); // I tried this and not working. Nothing is being SELECTED.
}
});
};
</script>
<input type="text" name="modsku" id="modsku" maxlength="10">
<select name="modproduct" id="modproduct">
<option></option>
<option value="Product1">Product1</option>
<option value="Product2">Product2</option>
<option value="Product3">Product3</option>
</select>
For what I am looking to have done is something like this.
<select name="modproduct" id="modproduct">
<option></option>
<option value="Product1">Product1</option>
<option value="Product2" selected>Product2</option>
<option value="Product3">Product3</option>
</select>