admin管理员组

文章数量:1434890

This is for generating the table.

function makeTable()
{
var row_num = 20;
var cell_num = 4;

var tab = document.createElement('table');
tab.setAttribute('id','newtable');
var tbo = document.createElement('tbody');
tbo.setAttribute('id','tabody');
var cont;
for(var c = 0 ; c < row_num ; c++)
{
    var row = document.createElement('tr');
    for(var k = 0 ; k < cell_num ; k++)
    {
        var cell = document.createElement('td');
        if (k > 0)
        {
            cont = document.createElement("input");
            cont.setAttribute('type','text');
        }
        else
        {
            cont = document.createTextNode("0" + (c+1));
        }
        cell.appendChild(cont);
        row.appendChild(cell);
    }
    tbo.appendChild(row);
}
tab.appendChild(tbo);
document.body.appendChild(tab);
tab.setAttribute("align", "top-left");
}

This function is used to show the data in alert box but I want to retrieve document.getElementById('hide').value............

function GetCellValues()
{
    var rows = document.getElementsByTagName('tr');
     var str = '';
    for (var c = 1 ; c < rows.length ; c++)
    {
        str += '\n';
        var row = rows[c];
        var inputs = row.getElementsByTagName('input');                
        for (var k = 0 ; k < inputs.length ; k++)
        {
            str += inputs[k].value + ', ';
        }

    }   
    document.getElementById('hide').value = str; 

I want to retrieve only this hidden control (i.e-"hide") in php.

    alert(document.getElementById('hide').value); 
}


window.onload = function()
{
    makeTable();
};

</script>
    </head>
    <body>
      <h1><u>PROJECT</u> :</h1>
      <input type="button" value="Alert" onclick = "GetCellValues()">

I want to retrieve this id in php

      <input type="hidden" id="hide" /> <br />



      <div id="mytable">
       <table id = "project" border = "1" width ="60%" class = "newtable" cellpadding="10" cellspacing="0">
       <tr>
         <th align="center" width ="200px">Sl.No.</th>
         <th align="center" width ="200px">Project Name</th>
         <th align="center" width ="200px">ChangeDate</th>
         <th align="center" width ="200px">Changed By</th>
      </tr>
      </table>
     </div>
     </body>

Note: I want to retrieve the hidden control through id in php ##

I want the total php code to retrieve this hidden control data(i.e-input type="hidden" id="hide") because I'm a beginner

This is for generating the table.

function makeTable()
{
var row_num = 20;
var cell_num = 4;

var tab = document.createElement('table');
tab.setAttribute('id','newtable');
var tbo = document.createElement('tbody');
tbo.setAttribute('id','tabody');
var cont;
for(var c = 0 ; c < row_num ; c++)
{
    var row = document.createElement('tr');
    for(var k = 0 ; k < cell_num ; k++)
    {
        var cell = document.createElement('td');
        if (k > 0)
        {
            cont = document.createElement("input");
            cont.setAttribute('type','text');
        }
        else
        {
            cont = document.createTextNode("0" + (c+1));
        }
        cell.appendChild(cont);
        row.appendChild(cell);
    }
    tbo.appendChild(row);
}
tab.appendChild(tbo);
document.body.appendChild(tab);
tab.setAttribute("align", "top-left");
}

This function is used to show the data in alert box but I want to retrieve document.getElementById('hide').value............

function GetCellValues()
{
    var rows = document.getElementsByTagName('tr');
     var str = '';
    for (var c = 1 ; c < rows.length ; c++)
    {
        str += '\n';
        var row = rows[c];
        var inputs = row.getElementsByTagName('input');                
        for (var k = 0 ; k < inputs.length ; k++)
        {
            str += inputs[k].value + ', ';
        }

    }   
    document.getElementById('hide').value = str; 

I want to retrieve only this hidden control (i.e-"hide") in php.

    alert(document.getElementById('hide').value); 
}


window.onload = function()
{
    makeTable();
};

</script>
    </head>
    <body>
      <h1><u>PROJECT</u> :</h1>
      <input type="button" value="Alert" onclick = "GetCellValues()">

I want to retrieve this id in php

      <input type="hidden" id="hide" /> <br />



      <div id="mytable">
       <table id = "project" border = "1" width ="60%" class = "newtable" cellpadding="10" cellspacing="0">
       <tr>
         <th align="center" width ="200px">Sl.No.</th>
         <th align="center" width ="200px">Project Name</th>
         <th align="center" width ="200px">ChangeDate</th>
         <th align="center" width ="200px">Changed By</th>
      </tr>
      </table>
     </div>
     </body>

Note: I want to retrieve the hidden control through id in php ##

I want the total php code to retrieve this hidden control data(i.e-input type="hidden" id="hide") because I'm a beginner

Share Improve this question edited Nov 9, 2013 at 6:33 zzlalani 24.5k16 gold badges47 silver badges73 bronze badges asked Nov 9, 2013 at 6:16 user2971243user2971243 131 gold badge1 silver badge3 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 0

You have to add a name to your input so for example:

<input type="hidden" id="hide" name="foo" />

To retrieve the value in php after POST form submission you can do this:

<?php $var1 = $_POST["foo"]; ?>

Can you please replace this line

<input type="hidden" id="hide" />

to

<input type="hidden" id="hide" name="hide" />

and use $_POST["hide"] in you php script.

Input field must have some name to access it

<input type="hidden" id="hide" name="hide" />

do normal fetch

$name = $_POST['hide']; 

add name property to input type and value you want to get into you php

<input type="hidden" id="hide" name="flag" value="1" />

and to retrieve the value in php after POST form

$var1 = $_POST["flag"];

本文标签: javascriptHow to get the value of html ltinput type“hidden” idquothidequotgt in PHPStack Overflow