Saturday, 15 March 2014

javascript - Enable button when text entered in dynamically added textboxes -


I have a form that takes input in the text box. First I display 1 text box, then on the button By clicking (add), the second text box shows. If none of the text boxes is empty then I want to disable the add button. My code is as follows:

  & lt; Script & gt; Function doCheck () {var allfilled = true; Var input = document.getElementsByName ("a []"); (Var i = 0; i & lt; inputs.length; i ++) {if (inputs [i] .type == "text" and input [i] .value == '') {allFilled = False; break; }} Document.getElementById ("add_a"). Disabled =! AllFilled; } Window.onload = function () {var inputs = document.getElementsByName ("a []"); (Var i = 0; i & lt; inputs.length; i ++) {if (input [i] .type == "text") {input [i] .onkeyup = doCheck; Input [i] .onblur = doCheck; }}}; Li & gt; input class = 'textbox' name = $ (document). $ (Document) .ready (function () {$ ("# add_a") click (function () {$ ("# A"). 'A []' type = 'text' size = '120' & gt; & lt; / li & gt; ");});}); & Lt; / Script & gt;  

This HTML part:

  & lt; Ol id = "a" & gt; & Lt; Li & gt; & Lt; Input class = "textbox" type = "article" name = "a []" size = "120" /> gt; & Lt; / Li & gt; & Lt; / Ol & gt; & Lt; Input class = "btn" type = "button" id = "add_a" value = "ADD" disabled = "true" & gt;  

This works for the first textbox, but which does not appear after clicking the Add Dynamically button. Please tell me how I can apply it to all

Here's a dirty version for you . I will come back and keep it under control if he will work for you. As other people have said, whenever you are using it, make full use of it.

  $ ("# add_a"). Click (function () {$ ("# a"). ("& Lt; li> input class = 'textbox' name = 'a []' type = 'text' size = '40' & gt; & Lt; / li & gt; "); $ (this) .prop (" disabled ", true);}); $ (Document) .on ("keyup", "#input"), function () {var blank input = $ ("#A"). ("Input"). Filter (function () {return $ .trim ($ (this) .val ()) == ""}). Length; $ ("# Add_a") Prop ("disabled", empty input);});  

Demo @


No comments:

Post a Comment