3

how do i bring the tr value into .click event? i want to be able to pass the tr id into updatedb.php as well- for sql updating

enter

<head>
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="jquery.jeditable.mini.js" type="text/javascript"></script>

<script type="text/javascript">

    $(document).ready(function() {

var global= ""

$('.click').click(function() {
    var $this = $(this);
    var $tr = $this.closest('tr');

alert($tr.attr('id'));
global= $tr.attr('id');

});


    $('.click').editable('updatedb.php?test=123', { 
        indicator : "<img src='indicator.gif'>",
        tooltip   : "Click to edit...",
        onblur : 'submit',
        style  : "inherit"

    });


    });

</script>

</head>
<body>      
    <tr id=1>
    <td>
        <span class="click" style="display: inline">Funny click here testing!</span>
        <br />
        </td>    
    </tr>
    <tr id=2>
        <td>    
        <span class="click" style="display: inline">Second inline!</span>
        </td>
    <tr>    
</body>
</html>

here

Hi, jeditable don't have successor. I finally manage to get the value into global. But now facing another issue. Jeditable doesn't allow me to pass in extra value...

I tried editable('updatedb.php?test=123' then echo "START" . $_POST['test'] . "END"

I also tried other way, not working.

1
  • 2
    Seems the html itself is very strange. you have a tr but without td, and you put the span inside and a br after that... I suggest you format your html properly first. Commented Jul 10, 2009 at 4:50

2 Answers 2

5

You may want to check out the jQuery plugin jEditable, the successor to editable. Link: http://www.appelsiini.net/projects/jeditable

Back to your question, you can get the id of the TR node in your example by asking for the attribute using either parent(), closest() or parents(). I'd recommend against parent() because it expects you to leave the HTML nested exactly like in your example. Better to use parents() or closest() with a filter.

$(document).ready(function() {
    $('.click').each(function() {
        var $this = $(this);
        var $tr = $this.closest('tr');
        // Do stuff with $tr like checking it, extracting $tr.attr('id') ...
        $this.editable('updatedb.php', {
            indicator : "",
            tooltip : "Click to edit...",
            onblur : 'submit',
            style : "inherit"
        });
    });
} 
Sign up to request clarification or add additional context in comments.

Comments

4
$(".click").click(function(){

 alert($(this).text())   // Funny click here testing! or Second inline!  (o/p);
 alert($(this).parent().parent().attr("id"))  // 1 or 2 (o/p);

});

1 Comment

if you want to return 1 or 2 then you should use $(this).parent().parent().attr("id") cause first parent is td, and parent of that is tr which holds id value

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.