Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

The attribute for input "onchange" will not fire, but "onkeydown" will, why?

Asked by Christopher Paterson Jun 12, 2023 1.6K views 1 answer
Share

About this question

 I am creating a lightning web component.

In the .html I have an input tag of type text, each time the user changes the field of this input I want to run a function on the input.

 <input class="my-input-class" id="date-of-birth-day" name="date-of-birth-day" type="number" onchange={validateNumberInput}></input>
And in the .js I have a simple function that should just console.log the word "hello"

import { LightningElement } from 'lwc'; export default class myClassHere extends LightningElement { day; month; year; validateNumberInput(event){ console.log("hello"); } }

When I type something into the input, validateNumberInput will not fire. However if I use onkeydown, it will fire.

Am I missing something here that would make onchange work?

Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.