javascript - Dynamically adding two form elements with jQuery -


I am trying to create two form elements when the user clicks a button, which he can do 5 times I'm new, I'm running into problems in JQuery,

Here's the code:

  $ (document) .ready (function () {$ ( '# BtnAdd') Length (var.) == ('.clonedInput') Length; var numTwo = $ ('.clonedInputTwo') Length; var newNum = New number (num + 1); var newElem = $ ( '# Etter (' id ',' input '+ new); var newElemTwo = $ (' # inputTwo '+ num2) .clone () .tr (' id ',' input '+ et (' id ',' name '+ New name) .attr ('name', 'name' + newNum); newElem.two.children ('first'). Attr ('id', 'name', + new name) .attr ('name', 'name $ ('#Enput' + num); $ ('#EntTwo' + num2) after $ ('newElem'); $ ('#BTNDL'); ('disabled', ' '); $ (' New Bundle ') $ (' # BtnAdd ') attr (' disabled ',' disabled ').)); $ (' #btndl ') click (function () {var num = $ ('ClonedInput'). Length; // We currently have $ ('# input' + num) how many "duplicate" input fields are. (); // Remove the last element $ ('# inputTwo' + num) .remove (); // Remove the last element // Enable the "add" button $ ('# btnAdd') attr ('disabled', ''); // If only one element remains, disable the "Remove" button if (num-1 == 1) $ ('# btnDel'). Attr ('disabled', 'disabled');}); $ ('# BtnDel') attr ('disabled', 'disabled'). });  

HTML:

  & lt; Form id = 'myForm' & gt; & Lt; Div id = 'input1' style = 'margin-down: 4px;' Class = 'clonedInput' & gt; Name: & lt; Input type = 'text' name = 'name1' id = 'name1' / & gt; & Lt; / Div & gt; & Lt; Div id = 'inputTwo1' style = 'margin-down: 4px;' Class = 'clonedInputTwo' & gt; School: & lt; Input type = 'text' name = 'nameTwo1' id = 'nameTwo1' / & gt; & Lt; / Div & gt; & Lt; Div & gt; & Lt; Input type = 'button' id = 'btned' value = 'add another name' /> & Lt; Input type = 'button' id = 'btn del' value = 'delete name' / & gt; & Lt; / Div & gt; & Lt; / Form & gt;  

When I click on the button, it works once, then it only makes income to create the name element, and there is no school element!

var newElem2 = $ ('# inputTwo' + num2) .clone () Attr ('id', 'input' + newNum);

should be

  var newElem two = $ ('# inputTwo' + num2) .clone () Attr ('id', 'input' two 'newNum);  

Take one (thanks for the mansion)


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -