$('input').each(function(){
var id = $(this).attr('id');
var class = $(this).attr('class');
var val = $(this).val();
if(val.length == 0){
alert('Error');
return false;
}
//HERE STOP UNTIL ALL IS OK
var data = '?id=' + id + '&class=' + class + '&val=' + val;
$.ajax({
type: 'POST',
url: url,
data: data,
success: success,
dataType: dataType
});
})
How to make this? I would like use $.ajax only if all input have length > 0.
for example if i have input:
1: [aaa]
2: [asad]
3: []
4: [sdfs]
then
1: - no error and send with ajax
2: - no error and send with ajax
3: - error and not send with - ajax previous return false
4: - stop script
In this example should be:
1: - no error - add to array and wait - not send with ajax
2: - no error - add to array and wait - not send with ajax
3: - error stop script - any data not send with ajax.
I would like send ajax only if all values are ok. How can i make it?
One option is to iterate twice, and use an indicator/flag variable to keep track of whether any validation failed: