简体   繁体   中英

Input change function doesn't trigger - jquery

I have a dropdown and a textbox .

I'm passing the dropdown value to a textbox.

And the dropdown I've created using jquery.dropdown . And so I can't directly write a function like $('.dropdown').change(function() {}) .

Now I wanted to write a function on textbox change.

I tried few functions. But nothing helped me out.

It only works if I manually type or press enter while focused on the textbox.

Fiddle .

Programatically changing a value does not trigger events, only user interaction does that.
You'd have to trigger the event yourself

$("input[name='textbox']").val(value).trigger('change');

FIDDLE

You can just use change function to trigger the event:

$('.dropdown').change(function() {

    $("input[name='textbox']").val(this.value).change()
})

Here Is your updated script

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM