javascript - Why is dynamic textbox returning empty value? -


A basic input textbox and a button are dynamically created through javascript using some bootstrap css. When I press the button, I have to get the value of the textbox. But it will be empty (not undefined).

DoSearch is the function where I need to take the price.

Here is JSField:

Here is the code:

  (function ($) {function doSearch () {warning ($ ('# name '). Val ()); // Is it empty? $ $ (Document.body) .on (' click ',' #go ', function () {alert (' searching '); doSearch () ;}); $ .fn.searchName = function () {var caller = $ (this); var output = ''; output = = 'div class = "input-group" & gt;' output = & Lt; span class = "input-group-addon area" id = "name" name = "name" & gt; name & lt; / span & gt; '; output + =' & lt; input type = " Text "Class =" Form-Control "/> Output = = '& lt; / div & gt;' Output + = '& lt; div class =" Input-group "& gt;'; Output T + = '& lt; span class = "input-group-btn" & gt;'; Output + = '& lt; button class = "btn btn-primary" type = "button" id = "go" & gt; ; Search & lt; / button & gt; '; Output + =' & lt; / span & gt; '; Output + =' & lt; / div & gt; '; Output + =' & lt; / div & Gt; '; $ (caller) .html (output); this refund;}} (JQuery)); $ (Document) .ready (function () {$ ('# searchName'). SearchName ();});    

id must be in the input Span instead of

  output + = '& lt; Span class = "input-group-addon area" & gt; Name & lt; / Span & gt; '; Output + = '& lt; Input type = "text" id = "name" name = "name" class = "form-control"  

Your update.


Comments