How to add jquery validation for dynamically added text input field

I need to check dynamically added text input box for below code

$("#btnadd").click(function() { // Made it a local variable by using "var" var addkey = document.getElementById("txtaddkey").value; if(addkey!=""){ $('<li><span>'+addkey+'</span><span class=\"amountin\"><a href=\"#\">$0.05</a> $ <input type=\"text\" maxlength=\"5\"/></span><span class=\'close ui-icon \'></span></li>') .find('.close').click(function (){ $(this).parent().remove(); }) .end().appendTo('#keyword'); $('#txtaddkey').val(''); } }); 
+4
source share
2 answers
+2
source

How to add jQuery any processing to dynamically added element

http://api.jquery.com/live/ - Live was designed for this purpose.

Given the added text field <input type='text' id='mytextbox'></input> , then this would be useful: ( NOTE : I recommend that you add an identifier to the text field if it will be displayed only once, or useful class name if it will be added again ~ Update the selector below to reflect the identifier or class)

 $('#mytextbox').live('keyup', function(event){ if ( $(this).val() == "fail value" ) { $(this).val() = "good value"; } }); 

It really depends on how you want to test it. The initial question doesn't really show how you are checking it now (if I am missing something)

+1
source

All Articles