Thursday 15 April 2010

jquery - Having trouble adding a textfield every time a key is pressed in the previous textfield -


I have just started, but I really like using jquery and here on other questions easily Looking for the answer but now the IM stuck with it. I have currently set it to alert: Pressed, but when a key is pressed I have tried to use ended to add a text field, but I'm coming with errors.

It should add a new taxfile down to the original Texfield when a user enters the key.

Thanks in advance.

  & lt; Script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script> & Lt; Input type = "text" name = "keydown" id = "keypress" /> & Lt; Script & gt; $ (Document) .ready (function () {$ ("# keypress") keydown (function () {warning ("pressed");});}); & Lt; / Script & gt;  

Add a class to your current textbox, still use event delegation: < / P>

  & lt; Input type = "text" name = "keydown" id = "keypress" class = "textboxpress" /> $ (Document) .ready (function () {$ (document) .on ('keydown', '.textboxpress', function () {$ (this) .after ("& lt; input type = 'text' class = 'Textboxpress' / & gt; ");});});   

After the focused box it will add a new textbox. If you have a specific container that you want to add, replace $ (this) with your container selector and after with append



No comments:

Post a Comment