/* comment_parsers.php */
<?php
/*if(isset($_POST["message"])){
echo $_POST["message"]." is information ";
exit();
}*/
echo 'Thank you '. $_POST['message'] . ' ' .', says the PHP file';
?>
The question is, how can I use this snippet to parse multiple textareas?
this gets the value in Javascript of the textarea when parsed. var m = document.getElementById("message").value;
But the problem is I am going to be outputting the textarea through a While loop, which means I can't have multiple id's.
So how can I get the value of each textarea, so that I can get the $POST value of each textarea?
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script>
<!-- ******** ajax.js ******** -->
function ajaxObj( meth, url ) {
var x = new XMLHttpRequest();
x.open( meth, url, true );
x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
return x;
}
function ajaxReturn(x){
if(x.readyState == 4 && x.status == 200){
return true;
}
}
</script>
</head>
<body>
<!--This will be output using a While loop for however many records are in the database. -->
<h2>Ajax Post to PHP and Get Return Data</h2>
<textarea id="message"></textarea> <br><br>
<button onclick="comment();">Post</button><br><br>
<textarea id="message"></textarea> <br><br>
<button onclick="comment();">Post</button><br><br>
<div id="status"></div>
</body>
<script>
function comment(){
var m = document.getElementById("message").value;
var vars = "message="+m;
if ( m ) { // check to see if m is an empty string or undefined
var ajax = ajaxObj("POST", "comment_parser.php");
ajax.onreadystatechange = function() {
if(ajaxReturn(ajax) == true) {
alert(ajax.responseText);
}
}
ajax.send(vars);
} else {
alert( "You must enter text." );
}
}
</script>
</html>