how to check if input field is empty

jquery

Solution

Use trim and val.

var value=$.trim($("#spa").val());

if(value.length>0)
{
 //do some stuffs. 
}

`val()` : return the value of the input.

`trim()`: will trim the white spaces.

Problem

I'm making a form with inputs, if the input type is empty then the button submit is disabled but, if the input fields is with length > 0 the submit button is enabled ``` <input type='text' id='spa' onkeyup='check()'><br> <input type='text' id='eng' onkeyup='check()'><br> <input type='button' id='submit' disabled> function check() { if($("#spa").lenght>0 && $("#eng").lenght>0) { $("#submit").prop('disabled', false); } else { $("#submit").prop('disabled', true); } } ``` it works but if then I delete for example the content of input spa the button submit is still enabled

Original source