Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
190
rated 0 times [  196] [ 6]  / answers: 1 / hits: 51359  / 12 Years ago, thu, november 22, 2012, 12:00:00

Is there a way to pass data to a change event via jQuery's trigger method?



The issue here is that a click event triggers the upload menu. Once the image is selected, the change event is fired, however. The data I passed into the trigger event's second parameter is passed to the click event, not to the change event. In the example below, data is undefined.



Trigger Image Change



$('.change_main_image').live('click', function() {
$('input[name=photo].change_uploader').trigger('click', [some string]);
});


Event Handler



$('input[name=photo].change_uploader').live('change', function (e, data) {
alert(data); // undefined
//canvas resize and upload script
});

More From » jquery

 Answers
6

.live() is deprecated. Use .on() like this. And change event should be triggered, not click



$('.change_main_image').on('click', function() {
$('input[name=photo].change_uploader').trigger('change', [{somedata:true}]);
});


$('input[name=photo].change_uploader').on('change', function (e, data) {
alert(data.somedata);
//canvas resize and upload script
});

[#81867] Tuesday, November 20, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jeffery

Total Points: 180
Total Questions: 114
Total Answers: 117

Location: Chad
Member since Mon, Dec 5, 2022
2 Years ago
jeffery questions
Fri, Jan 22, 21, 00:00, 3 Years ago
Wed, Dec 2, 20, 00:00, 4 Years ago
Mon, Apr 13, 20, 00:00, 4 Years ago
Mon, Feb 10, 20, 00:00, 4 Years ago
;