manage select boxes with jQuery


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // Get the value of the selected item
  2. $("#ComboBox").val();
  3.  
  4. // Get the text of the selected item
  5. $("#ComboBox option:selected").text()
  6.  
  7. // Find out when the select value changed
  8. $("#ComboBox").change(function() { /* do something here */ });
  9.  
  10. // Programmatically set the selected item.
  11. $("#ComboBox").val(2);
  12.  
  13. // Modify the list
  14. // Clear the list:
  15. $("#ComboBox").html("");
  16.  
  17. // Add to the list:
  18. $("<option value=’9’>Value 9</option>").appendTo("#ComboBox");

URL: http://elegantcode.com/2009/07/01/jquery-playing-with-select-dropdownlistcombobox/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.