santa
santa

Reputation: 12512

Warn if at least one value not empty

I have a set of form fields generated via a loop:

foreach ($arrays as $listValue) {
    echo '
    <div>
       <input type="text" maxlength="100" name="field[]">
    </div>';
}
<a href="#" id="myLink">link</a>

I also have a link below, that when clicked calls a jQuery function.

I'd like to add a check and display a warning (alert is fine) if there's at least one value present in the form fields when I click my link.

Upvotes: 2

Views: 1326

Answers (2)

Marek Karbarz
Marek Karbarz

Reputation: 29314

if($('input[value!=""]').length > 0) {
    //at least one field is filled out 
}

Upvotes: 5

Abe Petrillo
Abe Petrillo

Reputation: 2447

$(':input').each(function(){
     if($(this).val() != '')
     {
        alert('warning');
     }
})

Upvotes: 2

Related Questions