wie Sie schreiben javascript-code innerhalb von php

Ich habe ein Formular, Klick auf den submit-button:

<form>
   <h2 style="text-align: center">* * * PROJECTS * * *</h2>
<br>
   <input type="button" name="submit" onclick="document.write('<?php GetCellValues() ?>');" Value="SAVE">
<br>
</form>

<?php
    function GetCellValues()
    {
        echo("Save");
        var str = '';
        var rows = document.getElementsByTagName('tr');
        var table=document.getElementById("project");
        for (var i=0;i<table.rows[0].cells.length;i++)
        {
            str = str + (table.rows[0].cells[i].innerHTML) + ', ' ;     
        }
        for (var c = 1 ; c < rows.length ; c++)
        {
            str += '\n' + "0" + c + ', ';
            var row = rows[c];
            var inputs = row.getElementsByTagName('input');                
            for (var k = 0 ; k < inputs.length ; k++)
            {
                str += inputs[k].value + ', ';
            }
        }
    }
?>

<?php
$handle = fopen("data.csv", "w");
$hide = $_REQUEST['hide'];
fwrite($handle,$hide);

$file = file('data.csv');
$lines = count($file);

echo'<table id = "projest" border = "1" cellpadding="2" cellspacing="0" style = "width: 60%; margin-left: auto; margin-right: auto; border-color: brown; background-color:gray;">';
echo'<tr cellpadding="100">
    <th width="15%"><h3>Sl.No.</h3></th>
    <th width="15%"><h3>Project Name</h3></th>
    <th width="15%"><h3>ChangeDate</h3></th>
    <th width="15%"><h3>Changed By</h3></th>
</tr>';
for ($i=1; $i<$lines; $i++) 
{

  $part = explode(',', $file[$i]);

  echo'<tr>
    <td align= "center" width="5%">'.$part[0].'</td>
    <td align= "center" width="25%"><input type="text" value='.$part[1].'></td>
    <td align= "center" width="25%"><input type="text" value='.$part[2].'></td>
    <td align= "center" width="25%"><input type="text" value='.$part[3].'></td> 
  </tr>';
}
echo'</table>'; 
?>

Aber nicht in der Lage, das Formular zu senden, wenn ich den Aufruf der javascript-code auf onClick, es funktioniert.was ist das problem in diesem code gibt es eine Arbeit um für dieses?

InformationsquelleAutor user2995144 | 2013-11-19
Schreibe einen Kommentar