简体   繁体   中英

Jquery Jeditable Codeigniter sends multiple values

I have an ID that is Databases ID of the row I want to update, then is the new value that is submited, when pressing enter. What I want to do is assign the database cell which needs to be updated as a rel value. At the moment it only submits db_cell_1 no matter which cell I press to edit. If I press the second cell in my html page, I want it to submit db_cell_2 I hope that I made myself clear about the problem I'm facing. Any pointers in the right direction will be appreciated.

HTML:

<td  id="<?echo $value['ID'];?>" class="merv_editable" rel="db_cell_1" style="text-align: left;" > <?echo $value['nom_nosauk'];?></td>
<td id="<?echo $value['ID'];?>" class="merv_editable" rel="db_cell_2"><?echo $value['merv'];?></td>

JQuery:

$('.merv_editable').click(function(){

  var attrval = $(this).attr('rel');

    $('.merv_editable').editable('http://www.draugiem.lv',{
        id   : 'elementid',
        name : 'newvalue',
        submitdata : {pzid : attrval}
    });
});

The issue is related to using the class as the invoker of the editable call. Since you are already inside one instance of potentially many from a class (from the click event is of a single element) you have scope of $(this) which references just the singular element that was clicked. You can then pass this element to the editable call to invoke the correct element, not just the first one in source code.

To rectify, the code simply needs to reference the currently invoked element, which is shortcut with the $(this) directive.

$('.merv_editable').click(function(){
      var attrval = $(this).attr('rel');

    $(this).editable('http://www.draugiem.lv',{
        id   : 'elementid',
        name : 'newvalue',
        submitdata : {pzid : attrval}
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM