Search code examples
javascriptjqueryhtmlhidden-field

How to create and remove an HTML hidden field using jQuery?


First of all here is my code so that you can test it to see what's wrong: JSFiddle

I want to create a new hidden field every time the user selects from the left <select> element and remove / destroy the hidden field when the user clicks the right <select> element.

I used the jQuery command $("<input type='hidden' value=selectedAddFootballPlayerId>"); but when I checked of Firebug I can't see any hidden field being created. For removal of the hidden field I really don't know.


Solution

  • I think you are confused when defining the selector or where you want to display your new item. Try with this (I use text inputs):

    http://jsfiddle.net/Lzw4e/6/