0

I wanting to get the currentTarget to pass to a function, once I have changed the value of a select programmatically.

Is this possible? Something like,

$('input[name="client_id"]').val(model.get('id')) //Change the value of select
this.doSave( $('input[name="client_id"]')); //Do save expects event(e) as parameter

function doSave(event){
    console.log($(event.currentTarget);
}

I have simplified this down massively, basically I am changing a select programmatically, and then want to fire my save event, which normally gets triggered on a change event, and as a result takes an event as a parameter, but all I have is the DOM element? Is there a way to send it an event?

2 Answers 2

1

Use the change event handler as below :

$('input[name="client_id"]').on('change', function(event) {
   console.log($(event.currentTarget);
});

or

$('input[name="client_id"]').on('change', doSave);

function doSave(event){
    console.log($(event.currentTarget);
}
Sign up to request clarification or add additional context in comments.

Comments

0

First of all, This

$('input[name="client_id"]')

apparently, changes the value of an input and not select.

This

$('select[name="client_id"]').val(model.get('id'))

changes the selected option in a select.

You can bind the change event on a select like

$('select').change(function(event){
    //use event here 
    //or pass to doSave(event)
});

and it will be fired when call

$('input[name="client_id"]').change();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.