1

Currently the following code is able to make the first 2 columns editable and process it and have it sent to PHP and update to db. I then tried a few code to remove a particular row with the JavaScript code but now it caused that editable and delete to not work altogether.

How to make both editable and delete row work again?

Edit the editable uses source from jquery.jeditable.mini.js

HTML code:

<table>
<tbody><tr>
    <th>Room Types</th>
    <th>Acronym</th>
    <th>Delete</th>
</tr>
<tr id="row-0">
    <td><div class="edit" id="Deluxe Family">Deluxe Family</div></td>
    <td><div class="edit" id="DLX (2K)">DLX (2K)</div></td>
    <td><div class="delete" id="DLX (2K)"><span class="ui-button-text">X</span></div></td>
</tr>
<tr id="row-1">
    <td><div class="edit" id="Deluxe Queen">Deluxe Queen</div></td>
    <td><div class="edit" id="DLX (2Q)">DLX (2Q)</div></td>
    <td><div class="delete" id="DLX (2Q)"><span class="ui-button-text">X</span></div></td>
</tr></tbody>

Javascript:

$(document).ready(function() {
    $('.edit').editable('process.php', {
        loadurl   : 'load.php',
        id        : 'rt_code',
        name      : 'rt_codevalue',
        indicator : 'Saving...',
        tooltip   : 'Click to edit...'
    });
    $('.delete').click(function(){
        var del_id = $(this).attr('id');
        var rowElement = $(this).parent().parent(); //grab the row

        $.ajax({
                type:'POST',
                url:'process.php',
                data: delete_id : del_id,
                success:function(data) {
                    if(data == "YES") {
                       rowElement.fadeOut(500).remove();
                    } 
                    else {
                    }
                }
        });
    });
});

PHP:

if (isset($_POST['rt_code'])  {
    echo $_POST['rt_codevalue'];
}

if(isset($_POST['delete_id'])) {
    $data = "DELETE FROM roomtype WHERE RT_CODE = ".$_POST['delete_id'];
    if(query($data)) {
        echo "YES";
    }
}
6
  • 1
    id is unique and you're using the same id twice. Commented May 13, 2014 at 5:07
  • are you getting any erros on browser console? Commented May 13, 2014 at 5:08
  • how are you adding the rows. Commented May 13, 2014 at 5:08
  • @Itay Gal, i changed the value of ID to unique but still break editable and delete. Commented May 13, 2014 at 5:16
  • @BhushanKawadkar, no i'm not getting any error. Commented May 13, 2014 at 5:19

1 Answer 1

1

I guess error is in your jquery ajax code change it to as following,

$.ajax({
            type:'POST',
            url:'process.php',
            data: {delete_id : del_id},
            success:function(data) {
                if(data == "YES") {
                   rowElement.fadeOut(500).remove();
                } 
                else {
                }
            }
    });

actually the data you have passed seems like an object but you forgot to put braces '{}' i mean

  data: delete_id : del_id, 

should be

data: {delete_id : del_id},
Sign up to request clarification or add additional context in comments.

4 Comments

This still didn't remove the table row. It does solve the edit issue. Any other method?
I would suggest you alert the response from the AJAX script may be the response is not YES so that it is not getting in to the 'if' condition. i dont see any error in the code which is supposed to remove the table row.
I just tried again the answer given, yes it does work now, it is my process.php issue. I can't seems to vote your answer as i do not have 15 reputation yet. will come back and give you a vote once i gathered 15 reputation. Thanks!
U r welcome mate. i am glad i cud help. you can just mark my answer as 'Accepted Answer' as the owner of the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.