How can I access 'this' in the jeditable jquery plugin?

dirknibleck
dirknibleck used Ask the Experts™
on
I am using the jeditable plugin, and trying to add an attribute from the element to the ajaxSubmit. When I try to reference 'this' in my hash, it outputs null. Suggestions?
$('.edit').editable('<?php echo $_SERVER['PHP_SELF']; ?>', {
	cssclass : 'input',
	name : "title",
	submitdata : {ajax : 1, editable: 1, table_id: $(this).attr("name")}
});

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David H.H.LeeDigital Marketing (Hospitality)

Commented:
Hi dirknibleck,
Try this:
eg:
        submitdata : {ajax : 1, editable: 1, table_id: this.name}

Author

Commented:
no luck.

I still get a blank in the post data. The table_id key exists, though.
David H.H.LeeDigital Marketing (Hospitality)

Commented:
Ok, it seem like the table_id has been referred correctly. I'm not sure how you submit the data via integrated. Perhaps you try to perform a simple data submission first in your testing code?
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
I'm not sure what you mean. How would I perform a simple data submission? jeditable handles the ajax post.
David H.H.LeeDigital Marketing (Hospitality)

Commented:
Hi dirknibleck,
Possible post the complete related source code here for further inspection?

Author

Commented:
Hi x_com,

The related source code is the jeditable plugin, available @ http://www.appelsiini.net/projects/jeditable.

Yesterday I was playing around with other options, and I decided to use the option of submitting the editable to a function instead. The function seems able to successfully access "this".

David H.H.LeeDigital Marketing (Hospitality)

Commented:
Hi dirknibleck,
Ok, it seem like you have resolved the problem. I'm glad to hear that. You may post the solution that you used and refund your point according.
End result was to use a function in the place of the contained AJAX. As per below...


$(".edit_area").editable(function(value, settings) { 
				var curDate = new Date();
				var date_string = curDate.getFullYear() + "-" + curDate.getMonth() + "-" + curDate.getDate() + " " + curDate.getHours() + ":" + curDate.getMinutes();
				
				var el = $(this);
				var name = el.attr("name");
				var id = el.attr("id");
				
				$.post("index.php", {form_name : "test", form_type : "update", ajax : 1, editable: 1, table_id: name, details: value, entered_on: date_string, entered_by: 1});
				return(value.replace(/\n/gi, "<br />"));
 			}, {cssclass : "input", submit: "Ok", type: "textarea", onblur: "submit", data: function(value, settings) {
      				/* Convert <br> to newline. */
      				var retval = value.replace(/<br[\s\/]?>/gi, "\n");
      				return retval;
   					}
   			});

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial