0

I want to get the values from a form which was send to the page using javascript. here is my javascript function and form.

<?php
echo"<html>";
echo"<script type='text/javascript'>";
echo"function submitform(){";
echo"document.getElementById('myform').submit();}";
echo"</script>";
echo"<form id='myform' action='comment.php' method='post'>";                        
echo"<tr>";
echo "<td><img src='photos/$file' alt='$file'><br></td>";
echo "<tr><td><a href=\"delete.php?id=".$file."\" onclick=\"return confirm('You want to delete .$file???');\">".$file."</td></tr>";
echo "<tr><td><a href=\"like.php?id=".$file."\">like</td></tr>";
echo "<tr><td>".$result."likes</td><tr>";   
echo "<tr><td><a href=\"dislike.php?id=".$file."\">unlike</td></tr>";
echo "<tr><td>".$result1."unlikes</td><tr>";
echo"<tr><td colspan='2'>Your Comment: </td>";
$_SESSION['comment']=$file;
echo" <td colspan='5'><textarea name='comment' id='comment' rows='2' cols='25' ></textarea></td></tr>";
echo"<tr><td colspan='2'><a href='javascript: submitform()'>Comment</a></td></tr>";
//echo"<td><form name='up' action='delete.php' method='post' enctype='multipart/form-data></td>";
//echo"<td><a href='http://127.0.0.1/delete.php'><button  name='button' type='submit' value='photos'>delete</button></a></td>";

//$_SESSION['comment']=$file;
echo"</form>";
echo"</tr>";
?>
prakashfire
  • 33
  • 1
  • 7
  • 1
    Duplicate:http://stackoverflow.com/questions/11563638/javascript-get-input-text-value – Mani Sep 30 '13 at 09:53

2 Answers2

0

In the comment.php file the values are available in the $_POST array.

$_POST['comment'] // -> what the user wrote in the textarea.
Tibos
  • 27,507
  • 4
  • 50
  • 64
0

first in comment.php use print_r($_POST) and check data is get or not.

and you use post method to send data so you can get value using $_POST['field_name'].

and try to make html,javascript and php code like this:

<html>
<script type='text/javascript'>
function submitform(){
   document.getElementById('myform').submit();
}
</script>
<form id='myform' action='comment.php' method='post'>                       
<tr>
 <td><img src='photos/<?php echo $file;?>' alt='<?php echo $file;?>'><br></td>
  :
  :
 </tr>
</form>
</html>
DS9
  • 2,995
  • 4
  • 52
  • 102