title: Hidden input value to php session
body: <p>I have a form, which uses the following input towards the end:</p>
  
  <pre><code>&lt;input type="hidden" id="ct_count" name="ct_count" value=""/&gt;
  </code></pre>
  
  <p>The initialisation of the form is:</p>
  
  <pre><code>&lt;form action="email_submission.php" method="post" id="form1" onsubmit="mySubmit();"&gt;
  </code></pre>
  
  <p>And the mySubmit function is: </p>
  
  <pre><code>function mySubmit() {
    document.getElementById('ct_count').value = ct;
    document.getElementById("form1").submit();
  }
  </code></pre>
  
  <p>When i hit submit, I want to pass the value of ct, which is a variable count on the page, to email_submission.php and store it in a session variable. The session variable is returning blank on every submit, and i'm unsure if the value of the "ct" variable used is being passed through on the hidden field. </p>
  
  <p>Is someone able to pick up where i'm going wrong? There are already variables stored correctly through this, so it's not my session settings as far as i know. </p>
  
  <p>tldr: What's the correct way to take a javascript variable count and pass it through form submit to php? </p>
  
  <p>EDIT: 
  this is the code for adding fields.
  intiial loop for the variable "ct"</p>
  
  <pre><code>function new_link()
  {
  ct++;
  &lt;?php $ct = $ct + 1; ?&gt;
  
  document.getElementById("sec4_lender").setAttribute('name', 'sec4_lender_&lt;?php echo $ct;?&gt;');
  document.getElementById("sec4_balance").setAttribute('name', 'sec4_balance_&lt;?php echo $ct;?&gt;');
  document.getElementById("sec4_termdate").setAttribute('name', 'sec4_lender_&lt;?php echo $ct;?&gt;');
  document.getElementById("sec4_security").setAttribute('name', 'sec4_security_&lt;?php echo $ct;?&gt;');
  document.getElementById("sec4_description").setAttribute('name', 'sec4_description_&lt;?php echo $ct;?&gt;');
  document.getElementById("sec4_status").setAttribute('name', 'sec4_status_&lt;?php echo $ct;?&gt;');
  document.getElementById("sec4_repayment").setAttribute('name', 'sec4_repayment_&lt;?php echo $ct;?&gt;');
  document.getElementById("sec4_repayment2").setAttribute('name', 'sec4_repayment_2_&lt;?php echo $ct;?&gt;');
  
  var div1 = document.createElement('tr');
  div1.id = 'sect4busloan_div_'+ct+'';
  // link to delete extended form elements
  var delLink = '&lt;tr style="text-align:right;margin-right:65px"&gt;&lt;a href="javascript:delIt('+ ct +')"&gt;Del&lt;/a&gt;&lt;/tr&gt;';
  div1.innerHTML = document.getElementById('newlinktpl').innerHTML + delLink;
  document.getElementById('newlink').appendChild(div1);
  
  }
  
  // function to delete the newly added set of elements
  function delIt(eleId)
  {
  d = document;
  var ele = d.getElementById(eleId);
  var parentEle = d.getElementById('newlink');
  parentEle.removeChild(parentEle.childNodes[eleId]);
  var newct = ct - 1;
  ct = newct;
  &lt;?php $ct = $ct - 1;?&gt;
  
  }
  </code></pre>