xhelle Posted January 24, 2011 Share Posted January 24, 2011 Hi to all, I just need your help here... I'm just a newbie in ajax/javascript code... My problem is I need to update my database using a checkbox(onClick function) to validate. I try to alert all value I pass down but nothing happen in php... My query is correct because I try it using hard cord... I dont know were the problem here... hope someone here can help me... thanks I'll post the code here... [ajax code] function trim(stringToTrim){ return stringToTrim.replace(/^\s+|\s+$/g,""); } function validate(cb){ if(eval("document.myform.chbox[" + cb + "].checked")==true){ for(j = 0; j < 500; j++){ if(eval("document.myform.chbox[" + j + "].checked") == true){ document.myform.chbox[j].checked = false; if(j == cb){ document.myform.chbox[j].checked = true; var a1 = document.getElementById('lbG' + j).innerHTML; var a2 = document.getElementById('lbA' + j).innerHTML; var a3 = document.getElementById('lbE' + j).innerHTML; updateCustomerTable('1',a1,a2,a3); } } } } } var xmlhttpUpdate function updateCustomerTable(a0,a1,a2,a3){ xmlhttpUpdate=GetXmlHttpObject(); if (xmlhttpUpdate==null){ alert ("Browser does not support HTTP Request"); return; } xmlhttpUpdate.open('POST', 'updateCustTbl.php', true); xmlhttpUpdate.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlhttpUpdate.send("a0="+a0+"a1="+a1+"a2="+a2+"a3="+a3); //xmlhttpUpdate.send(null); xmlhttpUpdate.onreadystatechange=stateUpdate; } function stateUpdate(){ if (xmlhttpUpdate.readyState==4){ var a=xmlhttpUpdate.responseText; if(trim(a) == 'update'){ alert('Successfully Updated Record'); window.location.reload(true); } } } [/ajax code] $table = 'customer_table'; $act = isset($_POST['a0']) ? $_POST['a0'] : null; $count = isset($_POST['a1']) ? $_POST['a1'] : null; $id = isset($_POST['a2']) ? $_POST['a2'] : null; $landline = isset($_POST['a3']) ? $_POST['a3'] : null; if ($act == '1'){ echo $query = "UPDATE " .$table. " SET activity='0' WHERE count='$count' AND cust_id='$id' LIMIT 1"; $result = mysql_query($query, $conn); if ($result) { echo 'update'; } else { echo "<p>Error Damn it!: " . mysql_error() . "</p>"; } } $tblCust = 'customer_table'; $sql = "SELECT * FROM " .$dump2. " WHERE count > 0 GROUP BY count ASC"; $result = mysql_query($sql,$conn); if (mysql_num_rows($result) != 0) { $pager = new PS_Pagination($conn, $sql, 8, 5, 'param1=valu1¶m2=value2'); $rs = $pager->paginate(); $x1 = '#f6f6f6'; $x2 = '#f9f9f9'; $z = 0; $x = $x2; $cnt = 0; while($row = mysql_fetch_assoc($rs)) { $date = $row['date']; $y = substr($date,0,4); $m = substr($date,4,2); $d = substr($date,6,2); $id = $row['cust_id']; $sel = mysql_query("SELECT * FROM " .$tblCust. " WHERE cust_id = '$id' LIMIT 1"); while($rows = mysql_fetch_array($sel)){ $int = $rows['count']; $lname = $rows['last_name']; $fname = $rows['first_name']; $category = $rows['pricing_category']; $landLine = $rows['land_line']; $smart = $rows['smart_num']; $globe = $rows['globe_num']; $sun = $rows['sun_num']; $address = $rows['address']; $email = $rows['email']; $name = $lname.', '.$fname; } echo "<tr>"; echo "<td height='10px' style='background-color:".$x."'>"; echo $cnt; echo "<input type='checkbox' id='chbox' name='chbox' style='cursor:pointer' onClick='validate(".$cnt.")'></td>"; echo "<td height='10px' style='background-color:".$x."'><label id='lbA".$cnt."'>" .$id. "</label></td>"; echo "<td height='10px' style='background-color:".$x."'><label id='lbB".$cnt."'>" .$name. "</label></td>"; echo "<td height='10px' style='background-color:".$x."'><label id='lbC".$cnt."'>" .$y."/".$m."/".$d. "</label></td>"; echo "<td height='10px' style='background-color:".$x."'><label id='lbD".$cnt."'>" .$category. "</label></td>"; echo "<td height='10px' style='background-color:".$x."'><label id='lbE".$cnt."'>" .$landLine. "</label></td>"; echo "<td height='10px' style='background-color:".$x."'><label id='lbF".$cnt."'>" .$smart. "</label></td>"; echo "<td height='10px' style='background-color:".$x."'><label id='lbF".$cnt."'>" .$globe. "</label></td>"; echo "<td height='10px' style='background-color:".$x."'><label id='lbF".$cnt."'>" .$sun. "</label></td>"; echo "<td height='10px' style='background-color:".$x."'><label id='lbF".$cnt."'>" .$address. "</label></td>"; echo "<td height='10px' style='background-color:".$x."'><label id='lbF".$cnt."'>" .$email. "</label></td>"; echo "<td height='10px' style='display:none'><label id='lbG".$cnt."'>" .$int. "</label></td>"; echo "</tr>"; $cnt = $cnt + 1; if ($z == 0) { $x = $x1; $z = 1; }else{ $x = $x2; $z = 0; } } [/html and php] I wont complete the code in html part.... thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/225457-onreadystatechange-dont-pass-anythin/ Share on other sites More sharing options...
Firemankurt Posted January 28, 2011 Share Posted January 28, 2011 Not sure exactly what you have going on here but for starters, each element ID in your document must be unique. <label id='lbF".$cnt."'> is repeated several times. Quote Link to comment https://forums.phpfreaks.com/topic/225457-onreadystatechange-dont-pass-anythin/#findComment-1166342 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.