Pick values from a list


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



Copy this code and paste it in your HTML
  1. <!-- HTML -->
  2. <input type="text" id="input-text-4" size="40"/>
  3. <ul id="values">
  4. <li>Smashing Magazine</li>
  5. <li>Woork Up</li>
  6. <li>Mashable</li>
  7. </ul>
  8.  
  9. //JavaScript
  10. $("ul[id='values'] li").click(function suggestValues(){
  11. input = $("input[id='input-text-4']");
  12. el = $(this).html();
  13. $(this).remove();
  14. newinput = input.val();
  15. newinput = (newinput + el + ", ");
  16. input.val(newinput);
  17. });

URL: http://woorkup.com/2009/10/14/jquery-lessons-how-to-interact-with-html-forms/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.