The value of a field can not be null, it's always a string value.
The code will check if the string value is the string "NULL". You want to check if it's an empty string instead:
if ($('#person_data[document_type]').val() != ''){}
or:
if ($('#person_data[document_type]').val().length != 0){}
If you want to check if the element exist at all, you should do that before calling val
:
var $d = $('#person_data[document_type]');
if ($d.length != 0) {
if ($d.val().length != 0 ) {...}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…