Skip to content Skip to sidebar Skip to footer

How To Pass A Parameter To JQuery UI Dialog Event Handler?

I am currently trying to hook up jQuery UI dialog so that I may use it to create new items to my page and to modify ones existing already on the page. I managed in the former. I'm

Solution 1:

Perhaps following might suit your taste better:

Before $("#modify_exercise").dialog('open');, add

$("#modify_exercise").data('exercise_name',$(this).text());

and in the button callback, replace post_values.exercise_name = 'foobar'; with

 post_values.exercise_name = $(this).data('exercise_name');

Solution 2:

if you're working with eventhandlers you might want to use the event object instead of some global var ;)

event.target is what you're looking for.

e.g.

$('.sel').bind('dialogcreate', function(event, ui) {
event.target.innerHTML = 'new content';
});

Solution 3:

I can't think of how there is a connection between the clicked event and the dialog, so maybe the answer is just to use a global variable to store the name after each click event, and then use that in your dialog?

I've demonstrated this idea here: http://jsfiddle.net/NJa4U/

See how currentItem is used in that code.


Post a Comment for "How To Pass A Parameter To JQuery UI Dialog Event Handler?"