Unknown User
Unknown User

Reputation: 3668

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.

Upvotes: 1

Views: 201

Answers (2)

xiidea
xiidea

Reputation: 3394

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

Upvotes: 0

adeneo
adeneo

Reputation: 318182

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

Upvotes: 3

Related Questions