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.

  • 2
    See e.g. stackoverflow.com/questions/574941/… if it's a text field as it appears to be from the markup. – Keith C Mar 18 '16 at 15:36
  • it should work on change event. I can't see your code for Onchange. – Ricky Mar 18 '16 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. – Jitesh Goel Mar 18 '16 at 16:00
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 :)

| improve this answer | |
  • 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. – Jitesh Goel Mar 21 '16 at 11:01
  • Oh, Got it. I changed the above code as per your requirement. It should work now. Please check it once. – Raghavendhra Yarlagadda Mar 21 '16 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.