views:

2814

answers:

2

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.

+3  A: 
$(".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);

});
Srikanth
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
RaYell
+4  A: 

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"
        });
    });
}
dyve