-3

Is there anyway I can check if an input is empty using javascript and then run a function? I'd like it to be in the input itself if possible.

There is onChange so is there an ifEmpty lol?

3
  • Please update the question with the attempted code... Commented Feb 28, 2019 at 9:56
  • if (myElement.value == '') {runFunction();}JavaScript validation for empty input field Commented Feb 28, 2019 at 9:56
  • There is no ifEmpty attribute/event natively implemented, you need to take care of that by checking whether, on change, the value is effectively "empty" (define empty, anyway). Besides, can you please show what you've tried to accomplish the goal? Commented Feb 28, 2019 at 9:57

2 Answers 2

0
<input onChange="this.value.trim().length > 0 && myFunction()" />
Sign up to request clarification or add additional context in comments.

Comments

0

Try this

function a(e)
{
if(e.value=="")
return false;
else
console.log('there is a value')
}
<input value="" onclick="a(this)">

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.