title: Javascript random number in function onclick
body: <p>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.</p>
  
  <p>Any help?</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
       $(document).ready(function(){
       var i=1;
       var t = Math.floor(Math.random() * 256);
  
        $("#add_row").click(function(){
        $('#addr'+i).html("&lt;td&gt;"+ (i+1) +"&lt;/td&gt;&lt;td&gt;&lt;input name='need["+t+"][type]' type='text' placeholder='Name' class='form-control input-md'  /&gt; &lt;/td&gt;&lt;td&gt;&lt;input  name='need["+t+"][scope]' type='text' placeholder='Mail'  class='form-control input-md'&gt;&lt;/td&gt;&lt;td&gt;&lt;input  name='need["+t+"][priority]' type='text' placeholder='Mobile'  class='form-control input-md'&gt;&lt;/td&gt;");
  
        $('#tab_logic').append('&lt;tr id="addr'+(i+1)+'"&gt;&lt;/tr&gt;');
        i++;
    });
       $("#delete_row").click(function(){
       if(i&gt;1){
           $("#addr"+(i-1)).html('');
           i--;
           }
       });
  
    });
  </code></pre>
  
  <p></p>