1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

jQuery to update ORACLE DB is not Working with checkbox

Discussion in 'jQuery' started by chrishutagalung, Apr 16, 2014.

  1. #1
    Hi folks,

    first of all I am new here and i wanna say hello guys. I am working on a project that is stuck right now. So the idea is I have the checkboxes generated from the oci_fetch_array() into a table and when user check the checkbox, it automatically updates the database with corresponding data and disable the checkbox.

    My code is as follows,

    This is the jQuery
    $('.cuttingCheckbox').change(function() {
                 if (this.checked) {
                   $.post('process_class.php',{
                    headmark : $(this).data('headmark'),
                    headmark_id :  $(this).data('id')
                   }, function(response){
                        this.setAttribute("disabled", true), alert(headmark,headmark_id);
                   });
                   }
               });
    Code (JavaScript):
    and on the same page, I have the html markups,
    <?php               
           
        // IF SHOW KEY HAS BEEN PRESSED
        if($_POST['action'] == 'show')
            {           
            $sql   = "SELECT * FROM FABRICATION
                              WHERE FABRICATION.HEAD_MARK = '{$_POST["hm"]}'";
                             
            $query = oci_parse($conn, $sql);
                    $query_exec = oci_execute($query);
            
            while($row = oci_fetch_assoc($query)){
                        echo "<input type='hidden' id='headmarkid' value='".$row['HEAD_MARK']."' />";
                        echo "<input type='hidden' id='rowid' value='".$row['ID']."' />";
                          echo "<table border='1'>";
                                echo '<table cellspacing = "0"';
                                    echo '<thead>';
                                    echo '<tr><th>Head Mark/ID</th>
                                              <th>Cutting</th>
                                              </tr></thead>';
                                   
                                    echo "<tbody>";
                                    echo "<tr><td><b>$row[HEAD_MARK]/$row[ID]</b></td>";
                                   
                                              if ($row['CUTTING'] == 'Y'){                                  
                                                  //echo "<td><input type='checkbox' id='cuttingCheckbox'  name='cuttingCheckbox' checked='checked' disabled='disabled'/></td>";
                                                  echo "<td><img src='../images/fabDone.png' width='30' height='30'></td>";                                            
                                              } else {
                                                  echo "<td><input type='checkbox' data-headmark=".$row['HEAD_MARK']." data-id=".$row['ID']." class='cuttingCheckbox'  name='cuttingCheckbox'/></td>";
                                              }  
                                               
                                               echo "</tr>";
                                              echo "</tbody>";
                                    echo "<table cellspacing = '0'";
                    }
            echo "</table>";
         }//===> END OF 'SHOW'
    ?>
    PHP:
    and on the process_class.php I have this

    <?php
    
    $cuttingUpdateParse = oci_parse($conn,"UPDATE FABRICATION_QC SET CUTTING = 'Y'
                                           WHERE HEAD_MARK = ".$_POST["headmark"]." AND ID = ".$_POST["headmark_id"].";");
    $cuttingUpdateRes = oci_execute($cuttingUpdateParse);
    
    if ($cuttingUpdateRes){
        oci_commit($conn);
        echo "<script>alert('CUTTING UPDATED');</script>";
    } else {
        echo "<script>alert('CUTTING NOT UPDATED');</script>";
    }
    ?>
    PHP:
    The problem is when i click cutting, nothing happened. Please help me guys, any kind of help will be greatly appreciated

    cheers,
     
    chrishutagalung, Apr 16, 2014 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Your jQuery function is wrong - you need to assign $(this) to a variable inside the function to be able to reuse it inside $.post() - something like this:
    
    $('.cuttingCheckbox').change(function() {
        if (this.checked) {
            var $this = $(this);
            $.post('process_class.php',{
                headmark : $this.data('headmark'),
                headmark_id :  $this.data('id')
            }, function(response){
                $this.prop("disabled", true);
                alert(headmark,headmark_id);
              });
            }
      });
    
    Code (markup):
    That should at least trigger the function and return no errors. Besides, you would have seen the errors if you used Firebug's Console, or similar inspectors.
     
    PoPSiCLe, Apr 16, 2014 IP
  3. chrishutagalung

    chrishutagalung Greenhorn

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #3
    i did as you suggested but it still doesnt work. Firebug says this.prop / this.setAttribute is not a function
     
    chrishutagalung, Apr 16, 2014 IP
  4. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #4
    Then you didn't add the $this-variable. Just use the function as I copied above. And make sure you're using it within the document ready function.
     
    PoPSiCLe, Apr 17, 2014 IP