I want to change the text after i click using ajax
get the response text from ajax file and paste instead of the link
Also the div id in while loop is given in document.getElementById
PHP Code:
<?php
require 'connect.php';
?>
<html>
<head><title>Admin</title>
<link rel="stylesheet" type="text/css" href="tab_style.css">
<script type="text/javascript">
function getXMLHTTP() {
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}
return xmlhttp;
}
/*function approve(e) {
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
var getajax = req.responseText;
<!--document.myform.linkloc.value = req.responseText;-->
document.getElementById("getajax").innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", "approve.php?stu="+e, true);
req.send(null);
}
}*/
function block(b) {
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById("blk"+b).innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", "block.php?blo="+b, true);
req.send(null);
}
}
</script>
<script type="text/javascript">
function approve(e) {
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
<!--document.myform.linkloc.value = req.responseText;-->
document.getElementById("get"+e).innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", "approve.php?stu="+e, true);
req.send(null);
}
}
</script>
</head>
<body>
<?php
$admin_err='';
$pass_err='';
if (isset ($_REQUEST['submit'])) {
require 'connect.php';
$admin = $_REQUEST['admin'];
$pass = $_REQUEST['password'];
$err=0;
if($admin=="") {
$admin_err="enter username";
$err=1;
}
if($pass=="") {
$pass_err="enter password";
$err=1;
}
if ($err == 0) {
$check = mysql_query("SELECT admin FROM admin_login WHERE admin='".$admin."' and password='".$pass."' ");
$exi = mysql_num_rows ($check);
if($exi == 0) $err_msg = "Username/password combination incorrect.";
else {
$sel = mysql_query("SELECT * FROM stud");
echo "<h4 class='table-caption'>Students</h4>";
while ($fet = mysql_fetch_array($sel)) {
?>
<div class="base-layer">
<div class="table-row">
<div class="c_one"><p class="text"> <? echo $fet['name']; ?></p></div>
<div class="c_two"><p class="text"> <? echo $fet['email']; ?></p></div>
<div class="c_three"><p class="text"> <? echo $fet['school']; ?></p></div>
<div class="c_four"><p class="text"> <? echo $fet['subject']; ?></p></div>
<div class="c_five"><p class="text"> <? echo $fet['class']; ?></p></div>
<div class="c_six"><p class="text"> <? echo $fet['teacher']; ?></p></div>
<div class="c_seven" id="get<?php echo $fet['s_id']; ?>"><p class="text">
<?php if ($fet['approve'] == '1' ) {
echo "Approved";
}
elseif($fet['approve'] == NULL || $fet['approve'] == '0' ) {
?>
<a href="#" onClick="approve(<?php echo $fet['s_id']; ?>)"
style="text-decoration:none">
Approve</a>
<?php } ?>
</p>
</div>
<div class="c_eight" id="blk<?php echo $fet['s_id']; ?>"><p class="text">
<?php if ($fet['approve'] == '0' ) {
echo "Blocked";
}
elseif($fet['approve'] == '1') {
?>
<a href="#" onClick="block(<?php echo $fet['s_id']; ?>);" style="text-decoration:none">
Block
</a>
<?php } ?>
</p>
</div>
<div class="space-line"> </div>
</div>
</div>
<?php
}
die(mysql_error());
}
}
}
?>
<form id="formid" method="post" name="myform" action="">
<p>
<label for="username">Admin:</label>
<input name="admin" type="text" size="20" value="<?php if(isset($admin)) echo $admin; ?>" />
<?php echo $admin_err; ?>
</p>
<p>
<label for="pass">Password:</label>
<input name="password" type="password" value="<?php if(isset($pass)) echo $pass;?>" />
<?php echo $pass_err; ?>
</p>
<p>
<input name="submit" type="submit" value="Log in" >
</p>
<?php if(isset($err_msg)) echo $err_msg; ?>
</form>
</body>
</html>