I used a php for loop to create a block.the block has six fields.in javascript page i have to validate that block.(i.e) if any one field among six is empy
then it should show alert message.i have written conditions as follows
Code: Select all
var from_month = $("select[id='from_month']").map(function(){return $(this).val();}).get();
var to_month = $("select[id='to_month']").map(function(){return $(this).val();}).get();
var from_year = $("input[id='from_year']").map(function(){return $(this).val();}).get();
var to_year = $("input[id='to_year']").map(function(){return $(this).val();}).get();
var designation = $("input[id='designation']").map(function(){return $(this).val();}).get();
var company = $("input[id='company']").map(function(){return $(this).val();}).get();now i am writing condition as
Code: Select all
for(var i=0;i<3;i++)
{
if(from_month[i] != 'Month' && to_month[i] == 'Month' && from_year[i] == 'Year' && to_year[i] == 'Year' && designation[i] == 'Designation' && company[i] == 'Company')
{ alert("Enter all details for Experience "+(i+1));
break;
}
else if(from_month[i] != 'Month' && to_month[i] != 'Month' && from_year[i] == 'Year' && to_year[i] == 'Year' && designation[i] == 'Designation' && company[i] == 'Company')
{ alert("Enter all details for Experience "+(i+1));
break;
}
else if(from_month[i] != 'Month' && to_month[i] != 'Month' && from_year[i] != 'Year' && to_year[i] == 'Year' && designation[i] == 'Designation' && company[i] == 'Company')
{
alert("Enter all details for Experience "+(i+1));
break;
}
etc
}if i write conditions like this the number of lines of code is more.so any one have idea to make it simple using any loop..?