adsf
adsf

Reputation: 59

Check if a form field is not empty

I am trying to check if an input field is not empty. If not empty, process the form. The field is ID of ninja_forms_field_66. The problem is that when I enter "0" in this field, it thinks the field is empty and it won't pass validation.

$(document).ready(function() {  
    $('#ninja_forms_field_50').click(function() { 
        var ninja_forms_field_46=$( "#ninja_forms_field_46" ).val();
        if( (ninja_forms_field_46 !='' && ninja_forms_field_301 !='' && ninja_forms_field_66 !='undefined' && ninja_forms_field_71 !='' && ninja_forms_field_75 !='' && ninja_forms_field_304 !='' && ninja_forms_field_64 !='' && ninja_forms_field_63 !='' && ninja_forms_field_95.checked) || (document.getElementById("47_checklist").checked == true) )    

        {
        $.blockUI({ message: $('#rLo') });  
        }
    }); 
}); 

edit: I have tried it like ninja_forms_field_66 !='' and ninja_forms_field_66 !='undefined'

Upvotes: 0

Views: 84

Answers (3)

nejc.m
nejc.m

Reputation: 300

I would suggest that you use the string length function and check if it is bigger than 0 - str.length > 0. Example

Upvotes: 0

bcarn
bcarn

Reputation: 133

Try

if(ninja_forms_field_66) {...}

Upvotes: 0

Kevin Bowersox
Kevin Bowersox

Reputation: 94499

Check the length of the field: ninja_forms_field_46.length > 0

You should also trim the value:

 var ninja_forms_field_46= $.trim($("#ninja_forms_field_46" ).val());

Upvotes: 1

Related Questions