Passing javascript variable to php with other html variable using post method
<p>I want to send variable rows to <code>post2.php</code> with other HTML form variable using POST or GET methods.</p>

<p>The below code gives an error:</p>

<pre><code>Notice: Undefined index: row1 in C:\xampp\htdocs\PhpProject1\OtherUsableItems\post2.php on line 8
</code></pre>

<p><strong>post1.php</strong></p>

<pre><code> &lt;html&gt;
 &lt;head&gt;
 &lt;SCRIPT language="javascript"&gt;
 function addRow(tableID) {
      var table = document.getElementById(tableID);

      var rowCount = table.rows.length;
      var row = table.insertRow(rowCount);

      var colCount = table.rows[0].cells.length;

      for(var i=0; i&lt;colCount; i++) {
          var newcell = row.insertCell(i);

          newcell.innerHTML = table.rows[0].cells[i].innerHTML;
          //alert(newcell.childNodes);
          switch(newcell.childNodes[0].type) {
              case "text":
                      newcell.childNodes[0].value = "";
                      break;
              case "checkbox":
                      newcell.childNodes[0].checked = false;
                      break;
              case "select-one":
                      newcell.childNodes[0].selectedIndex = 0;
                      break;
          }
      }      
  }
  &lt;/script&gt;
  &lt;script&gt;
  function count(tableId){
      var rows = document.getElementById(tableId).getElementsByTagName("TR").length;

     // window.location.href = "http://localhost/PhpProject1/OtherUsableItem  /post2.php?rows=" + rows ;
     // alert('Your table has ' + rows + ' rows.');
     $.post("post2.php", { 'row' : rows}, function(rows){alert('rows'+rows);});
  }
  &lt;/script&gt;

  &lt;/head&gt;
  &lt;body&gt;
  &lt;form action="post2.php" method="post"&gt;

   &lt;TABLE id="dataTable"  border="1"&gt;
    &lt;TR&gt;
        &lt;TD&gt; 1 &lt;/TD&gt;
        &lt;TD&gt; &lt;INPUT name="n1[]"type="text" /&gt; &lt;/TD&gt;
        &lt;TD&gt; &lt;INPUT name="n2[]"type="text" /&gt; &lt;/TD&gt;
        &lt;TD&gt;&lt;SELECT name="country[]" type="select-one"&gt;
                &lt;OPTION value="in"&gt;India&lt;/OPTION&gt;
                &lt;OPTION value="de"&gt;Germany&lt;/OPTION&gt;
                &lt;OPTION value="fr"&gt;France&lt;/OPTION&gt;
                &lt;OPTION value="us"&gt;United States&lt;/OPTION&gt;
                &lt;OPTION value="ch"&gt;Switzerland&lt;/OPTION&gt;
            &lt;/SELECT&gt;&lt;/TD&gt;
    &lt;/TR&gt;
  &lt;/TABLE&gt;
 &lt;INPUT type="button" value="Add Row" onclick="addRow('dataTable');"/&gt;
 &lt;button id="bt" onclick="count('dataTable');"&gt;Submit&lt;/button&gt;
 &lt;/form&gt;

 &lt;/body&gt;
 &lt;/html&gt;
</code></pre>

<p><strong>post2.php</strong></p>

<pre><code>&lt;?php
    $n1 = $_POST['n1'];
    $n2 = $_POST['n2'];
    $country = $_POST['country'];
    echo $n1[0];
    echo $n2[0];
    echo $country[0];
    $count = $_POST['row1'];
    echo $count;
?&gt;
</code></pre>
