Reputation: 257
I am checking the number of wrong lines with a for loop
var lines = dateinput.value.split(/\r?\n/);
var wrongLines ="";
for(var i = 0; i<lines.length ; i++){
if (lines[i].match(regex) == null) {
wrongLines += i + 1 +",";
}
and I want to add different alerts for the number of the wrong lines
if (i = 1 ) {
alert('The date on line ' + wrongLines + ' is invalid. Please enter a valid date formatted DD/MM/YYYY');
}
else if (i > 1 ) {
alert('Dates on line ' + wrongLines + ' are invalid. Please enter a valid date formatted DD/MM/YYYY');
}
but it does not works - every time I get the first alert
Upvotes: -1
Views: 44
Reputation: 901
at first impression, you should replace if (i = 1)
with if (i == 1)
Upvotes: 0
Reputation: 25352
Try like this
if (i == 1 )
You are assigning values instead of comparing.
N.B. :
= means assigning
== means comparing
=== means strict comparing
Upvotes: 2