Need some help. with the below javascript. On inserting a row I need the random number t to generate a new number on each click (insert). I have to send each row to the processor as an array so that needs to be a unique number on each insert. I can get it to work the first time but of course it's just generating on load and not each click. Been at it for hours trying to figure it out... but no dice.
Any help?
<script type="text/javascript">
$(document).ready(function(){
var i=1;
var t = Math.floor(Math.random() * 256);
$("#add_row").click(function(){
$('#addr'+i).html("<td>"+ (i+1) +"</td><td><input name='need["+t+"][type]' type='text' placeholder='Name' class='form-control input-md' /> </td><td><input name='need["+t+"][scope]' type='text' placeholder='Mail' class='form-control input-md'></td><td><input name='need["+t+"][priority]' type='text' placeholder='Mobile' class='form-control input-md'></td>");
$('#tab_logic').append('<tr id="addr'+(i+1)+'"></tr>');
i++;
});
$("#delete_row").click(function(){
if(i>1){
$("#addr"+(i-1)).html('');
i--;
}
});
});
See Question&Answers more detail:os