Search code examples
jqueryjeditable

How do I get the ID of the clicked <td> for use by jeditable to pass into the loaddata URL?


I'm struggling using jeditable to create a JSON list of values from a table, then display them in the td for selection, and then save the new value using save.php. My issue is not with JSON however. Below is the HTML td I'm trying to edit with jeditable.

<td id="facility:95633" class="editable editfacility">Saint Lukes</td>

In order to create the dropdown list for selection I must have the value of the id from the clicked td to use in the where clause of the getListOfFacilities.php.

Function CellEditFunction( jQuery ) {
   Var submitdata = {};

$(".editfacility").editable("save.php", {
    type       : "select",
    submit     : "OK",
    style      : "inherit",
    loadurl    : "getListOfFacilities.php",
    Loaddata   : {recordID : this.id.split(":").pop()},
});
... and many, many more doing different things
} // End CellEditFunction

The problem here is I always get an error saying:

"Uncaught TypeError: this.id is undefined CellEditFunction https://net-control.us/js/CellEditFunction.js:99"

Line 99 is the loaddata definition. All things work if I pre-define (hardcode) var id="facility:95633"; before the editable definition, this tells me the rest of the code is working.

So my question becomes how do I get the value of id from the clicked td? I've googled and I've searched SO and none of those solutions work, such as: Jeditable Not Returning "id" Value Or var id = $('.editable').find("div:first").attr("id"); But using parent("td"), or closest("td") does not return the value.

If I try: var id = $(this).find('td:first').attr('id'); console.log("@95 id: "+id); I get the an error trying to use the id variable "Uncaught TypeError: id is undefined"

Without the id variable I can not pull the data needed to populate the dropdown. I'm hoping someone out there can see what I'm missing and help me to solve this issue.


Solution

  • var submitdata = {};
       $(".editfacility").click(function(){
          var recordID = $(this).attr("id").split(':').pop(); 
             submitdata['recordID'] = recordID;
                console.log(submitdata); 
       });
    

    But instead of using submitdata : submitdata I found i needed to use loaddata : submitdata otherwise it errored out.