Jump to content

onreadystatechange dont pass anythin


xhelle

Recommended Posts

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&param2=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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.