javascript - jQuery input forms issue -


i'm working on input forms in javascript, , i've edited script once user enters number of forces problem, new input text fields show per number, there button added @ end of that. issue when try , click button, try , use .map function start text field values , nothing happening.

function forcerecording(numofforces,$this){     var addrows='<tr id=newrows>';      for(var =1; i<=numofforces;i++)     {         var neartr=$this.closest('tr');         addrows=addrows + "<td>force " +i+": </td><td><form><input type='text' name='forceitem' id='newr'/></form></td>";     }      addrows=addrows+"<td><div class='button' id='forcebutton'> add! </div></td></tr>";     neartr.after(addrows); };  $('#forcebutton').click(function(){     forces=$("input[id='newr']").map(function(){     return $(this).val() });      function forcerecording(numofforces,$this){     var addrows='<tr id=newrows>';      for(var =1; i<=numofforces;i++)     {         var neartr=$this.closest('tr');         addrows=addrows + "<td>force " +i+": </td><td><form><input type='text' name='forceitem' id='newr'/></form></td>";     }      addrows=addrows+"<td><div class='button' id='forcebutton'> add! </div></td></tr>";     neartr.after(addrows); };  $('#forcebutton').click(function(){     forces=$("input[id='newr']").map(function(){         return $(this).val()     });      prompt("forces"); }); 

as can see forcerecording function working , creates new row new text input fields per numofforces once try clicking forcebutton enter values forces array nothing happens. idea causing this?

you missing closing paranthesis around code here

$('#forcebutton').click(function(){     forces=$("input[id='newr']").map(function(){return $(this).val() }); 

it should

$('#forcebutton').click(function(){    forces=$("input[id='newr']").map(function(){        return $(this).val();    }); }); 

and don't use id instead use class name

$('#forcebutton').click(function(){     forces=$(".newr").map(function(){         return $(this).val();     }); }); 

apply class input field this

<input type="text" name="forceitem" class="newr"/> 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -