简体   繁体   中英

How can I check multiple textbox if null or empty in Javascript?

How can I check multiple textbox if null or empty in Javascript ? I should know which textbox is filled

You can use the jquery .each function with a selector pointing to all the input elements with type "text". Something like this:

var nonNullInputs = new Array();
$(':text').each(function (index, value) {
    if ($(this).val() != null) {
        //get the id of the non null text input and push it for example in an array
        //the index parameter returns the number of the input element by order in the form,
        //the value parameter return the value
        nonNullInputs.push($(this).attr('id'));
    }
});
//now you have an array named nonNullInputs with all the inputs with type text which are not empty.

I Hope this helps :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM