Javascript detect select option change

Posted: assesor On: 26.05.2017

.change() | jQuery API Documentation

When a user pulls down the combobox and selects the same option that was previously selected or doesn't change the selection at all , JavaScript doesn't regard it as an onchange event. So, the jsFunction is not called. But I want the jsFunction called even in this case. How can I achieve this? If you want you could have the same label as the first option, which in this case is 1. I also can give you one more solution but its up to you that is fine for you or not Because User select default option after selecting other options than jsFunction will be called twice.

The only drawback is that when the user clicks on the dropdown list, the currently selected item does not appear selected. It's not firing because the value hasn't "changed". It's the same value. Unfortunately, you can't achieve the desired behaviour using the change event. You can handle the blur event and do whatever processing you need when the user leaves the select box.

That way you can run the code you need even if the user selects the same value. It works every time, removing the highlight and allowing you to select the same or different element again.

By posting your answer, you agree to the privacy policy and terms of service.

Stack Overflow Questions Developer Jobs Documentation beta Tags Users. Sign up or log in to customize your list. Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us.

Log In Sign Up. Join the Stack Overflow Community. Stack Overflow is a community of 7. Join them; it only takes a minute: HTML SELECT - Trigger JavaScript ONCHANGE event even when the option is not changed Ask Question. I have the following markup: Dilip Raj Baral 1, 5 18 Geoffrey I did think that too. That again brings up another problem.

javascript - how to detect when a user clicks on an option in a drop down menu (select tag) - Stack Overflow

How do I dynamically using JavaScript select the desired option entry with no value in this case? I'd do it like this: NickSuperb 6 Simon Aronsson 1, 6 And whenever I got to show the combobox, I set selecedIndex to 0. You have to add empty option to solve it, I also can give you one more solution but its up to you that is fine for you or not Because User select default option after selecting other options than jsFunction will be called twice.

Ben 1 7 Just add an empty option. This will solve your problem. Praveen Singh 1 5 Not a very goodlooking solution. When other option is selected and again the user selects the same option??

javascript detect select option change

Actually the situation is like this. I have a combox box. When any option is selected, I hide the combox and show the value of the combobox as a LABEL with the CHANGE option. When CHANGE is clicked, again I show that combobox. RajBD, yeah you won't be able to do that without handling blur and making them leave the select to update.

It's a minor usability issue though. I think it would be better if you give them an explicit option to "cancel", by placing a "Cancel" link next to the select box when you're showing it.

javascript - Changing the selected option of an HTML Select element - Stack Overflow

Pooya 3, 1 11 Dinsan Loord 1 1. This is not an answer to the asked question, which is about the behaviour of JavaScript change events. Sign up or log in StackExchange. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.

Stack Overflow works best with JavaScript enabled. Normally when I want this behaviour I add an extra entry with no value which is the default I tried ONCLICK before.. This will create an empty box at top, which is also selectable. MathOverflow Mathematics Cross Validated stats Theoretical Computer Science Physics Chemistry Biology Computer Science Philosophy more 3. Meta Stack Exchange Stack Apps Area 51 Stack Overflow Talent.

Rating 4,2 stars - 359 reviews
inserted by FC2 system