The Little Guy Posted December 2, 2011 Share Posted December 2, 2011 I am using jQuery and I have a drop down menu and when a user select the option "New Option" a text box is un-hidden they enter the new option, and press add. jQuery I send the value of the textbox to a php file which adds the option to the database, then I have a php function which rebuilds the drop down with the new value in it and the hidden box. I then add those to the page (over writing the old drop down and hidden textbox). The problem I am having is that I can do this one time the second time this no longer works unless I reload the page. What is causing this? Quote Link to comment Share on other sites More sharing options...
requinix Posted December 2, 2011 Share Posted December 2, 2011 It's probably because you destroyed the previous which means all its event listeners will disappear. Options include: a) Use jQuery's .live(). b) Reattach the event handler to the new . c) Have the PHP only output s; clear the of children and add those into it. d) Use JavaScript to add the new manually. This one is probably the best. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted December 2, 2011 Author Share Posted December 2, 2011 Thanks! live() works! I would rather not have to rebuild so I will go wit that one. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.