indexOf Select Change Function


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

Gets value of option from ” - “ and inserts it into specified input


Copy this code and paste it in your HTML
  1. //usage
  2. jQuery(document).ready(function() {
  3. $("select#yourselect").change(onSelectChange);
  4. });
  5.  
  6.  
  7. //function
  8. function onSelectChange(){
  9. var selected = $("select#yourselect option:selected");
  10. var output = "";
  11. if(selected.val() != 0){
  12. output = selected.text(result);
  13. var str = selected.text();
  14. var result = str.substring(str.indexOf(" - ") + 3,str.length);
  15. }
  16. $("input#yourinput").val(result);
  17. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.