title: passing a javascript variable into a hidden form in codeigniter
body: <p>I have a page in Codeigniter in which  i can set the product quantity (sq.m) that the client wants to buy. When the client sets the quantity i have to do some calculations (about the quantity number whis was set before) and i am doing that with Javascript setting some variables. Now i want to show these variables in the same (php) page and it's working, but i don't know what should i do to put these variables in the values of the hidden inputs so that i can send them to the controller. Here is the coding:</p>
  
  <pre><code>&lt;input type="text"  name="productQuantity"&gt;
  &lt;input type="button" class="button" onclick="return showHide();" value="Calculate Packs"&gt;
  
  &lt;script type="text/javascript" language="javascript"&gt;// &lt;![CDATA[
      function showHide() {
          var ele = document.getElementById("showHideDiv");
          if(ele.style.display == "block") {
              ele.style.display = "none";
          }
          else {
  &lt;?php $pack = explode(' ', $pro-&gt;productPackSize); ?&gt;
                  ele.style.display = "block";
  
                  var val = document.getElementById('productQuantity').value;
                  document.getElementById('val').innerHTML = val;
                  var req = Math.round(val/&lt;?php echo $pack[0]; ?&gt;);
                  document.getElementById('req').innerHTML = req;
                  var total = req * &lt;?php echo $pack[0]; ?&gt;;
                  document.getElementById('total').innerHTML = total;
  
              }
          }
          // ]]&gt;&lt;/script&gt;
  
  &lt;div id="showHideDiv" style="display:none;"&gt; 
      &lt;?php echo form_open('main/add_to_cart_validation/' . $pro-&gt;productId); ?&gt;
      To cover &lt;strong id="val"&gt;&lt;/strong&gt; sq.m,  you will need &lt;strong id="req"&gt;&lt;/strong&gt; Packs 
      which is &lt;strong id="total"&gt;&lt;/strong&gt; sq.m in total&lt;/a&gt; //the ids' here are working, i can show them in the page
  
  &lt;input type="hidden" id="" value="" name="productPacks"&gt; //how can i get the 'reg' variable here?
  &lt;input type="hidden" id="" value="" name="productQuantity"&gt; //the same here as above for 'total' variable
  &lt;input type="submit" class="button" value="Add to Cart"&gt;
  &lt;/form&gt;
  &lt;/div&gt;  
  </code></pre>
  
  <p>Thanks for your answers</p>