Reputation: 123
Any idea to my problems? I have to pass a value from json data on jquery change. My code look like this now :
$('#id_user').val(data.id_user).change(data.id_level); // need to pass this id_level
And need that data.id_level
in :
$('#id_user').change((howToPassThatIdLevelHere), function(){ // I need the id_level in here
...
})
Thank you
Upvotes: 0
Views: 39
Reputation: 484
You can use JSON
object to pass data through event.
//Declare of the change event's callback
$('#id_user').change(function(event, eventdata){
if(typeof eventdata !== 'undefined'){
var id_level = eventdata.id_level; //Way to get passing JSON object
}
});
//Trigger change event with JSON params
$('#id_user').val(data.id_user).trigger("change",{id_level: data.id_level});
Hint: The undefined
checking of eventdata
is required to avoid error occur, when the change
event triggered by user
Upvotes: 1