-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?

TiernO
  • 427
  • 6
  • 20
  • Please update the question with the attempted code... – Mamun Feb 28 '19 at 09:56
  • `if (myElement.value == '') {runFunction();}`[JavaScript validation for empty input field](https://stackoverflow.com/questions/3937513/javascript-validation-for-empty-input-field) – Justinas Feb 28 '19 at 09: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? – briosheje Feb 28 '19 at 09:57

2 Answers2

0
<input onChange="this.value.trim().length > 0 && myFunction()" />
Mihai Matei
  • 24,166
  • 5
  • 32
  • 50
0

Try this

function a(e)
{
if(e.value=="")
return false;
else
console.log('there is a value')
}
<input value="" onclick="a(this)">
ellipsis
  • 12,049
  • 2
  • 17
  • 33