Select radiobuttons, textfields and dropdown menys with jquery


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

Just so I remember the next time..


Copy this code and paste it in your HTML
  1. Radio button
  2. js:
  3. [$("input[@name='the_name']:checked").val()]
  4.  
  5. html:
  6. <input type="radio" name="the_name" value="0" /> Milk
  7. <input type="radio" name="the_name" value="1" /> Coffie
  8.  
  9. the_name is the name of several buttons, and it's the items value that is selected
  10.  
  11.  
  12. Same method on a textfield:
  13.  
  14. js:
  15. [$('input[@name="newCatField"]').val()]
  16.  
  17. html:
  18. <input type="text" id="newCatField" name="newCatField"/>
  19. same same.
  20.  
  21. On a dropdown menu:
  22.  
  23. js:
  24. $('#myid :selected').val()
  25.  
  26. html:
  27. <select id="myid">
  28. <option value="1">Nyhet</option>
  29. <option value="2">Sport</option>
  30. <option value="3">Utenriks</option>
  31. </select>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.