[Solved] Populating 2 textboxes using a single select menu using jQuery


If I was you, I would create an object with all of the info in it, using the values from the select as keys:

var values = {
  "1": {
    "price": "100",
    "description": "Important"
  },
  "2": { ... }
}

Then, hook into the change event and use the value of the selected option to look up the relevant details:

$("select").on("change", function(){
  var key = $("#myselect option:selected").val();
  var details = values[key];
  $("#description").val(details.description);
  $("#price").val(details.price);
  ...
});

This way you can keep everything in one place (a seperate file, for example) and remove all of those hard-to-read and hard-to-maintain data attributes.

2

solved Populating 2 textboxes using a single select menu using jQuery