0
<apex:inputText list="{!listOfStringElements}" id="userInput" onChange="alert(this.value);"></apex:inputText>

In the above code when I select any value from the listOfStringElements I want to call a javascript function. Onchange on the above code works when after selecting the value I click anywhere on the screen but I want to call it as soon as i select any value from the list.

3
  • 2
    See e.g. stackoverflow.com/questions/574941/… if it's a text field as it appears to be from the markup.
    – Keith C
    Commented Mar 18, 2016 at 15:36
  • it should work on change event. I can't see your code for Onchange.
    – Ricky
    Commented Mar 18, 2016 at 15:37
  • @Ricky onchange works when I select the value from the list and then click anywhere else on the page but I want the value in javascript function as soon as I select the value from the list. Commented Mar 18, 2016 at 16:00

1 Answer 1

3

Try Using 'html-oninput' instead on 'onChange'

Your code edited:

<apex:inputText list="{!listOfStringElements}" id="userInput" html-oninput="alert(this.value);"></apex:inputText>

I hope this helps :)

2
  • OnKeypress works when I enter the value using the keyboard but I want the alert when I click on any of the value from the dropdown list. Commented Mar 21, 2016 at 11:01
  • Oh, Got it. I changed the above code as per your requirement. It should work now. Please check it once. Commented Mar 21, 2016 at 16:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .