I'm working on a game and am using a table as a form in order for the player to fill out some information. I am using jQuery so that when the button is clicked after the number of players is input, a new text box appears for each name. The issue is I'd like these input fields to appear in rows below the number of players input box, but when I use the .after
jQuery function they end up going straight to the top of my table. I was wondering what I could do to add to the table by creating rows right underneath the current ones, or if you have any input on a method other than a table for an input form which I can manipulate, a lot? I've attached some of my code, for the functions that deal with .after
and the table, your input is much appreciated! :)
<div class=form>
<table>
<tr>
<td>Gender:</td>
<td><form>
<input type="text" name="genderItem"/>
</form>
</td>
<td>
<div class ="button" id="button1">Add!</div>
</td>
</tr>
<tr>
<td>Number of charcters:</td>
<td><form>
<input type="text" name="charcItem"/>
</form>
</td>
<td> <div class="button" id="button2">Add!</div> </td>
</tr>
<div id="holder"></div>
</table>
$('#button2').click(function(){
names=$('input[name=charcItem]').val();
nameRecording(names);
});
function nameRecording(names){
for(var i =1; i<=names; i++)
$('#holder').after('<tr><td>Name one:</td><td><form><input type="text" name="charcItem"/></form></td></tr>');
};