Reputation: 10709
I want to concatenate a string to display in a jquery alert
. I've followed the instructions, which seem pretty basic, on posts such as this, however I'm not having any luck.
For example, this jquery code
//Validate field values
var errors = "";
if (inputArray[0].length != 8) {
errors += "Life Master must be 8 digits"+'\\n';
}
if (inputArray[1].length != 3) {
errors += "Market Segment must be 3 digist" + '\\n';
}
if (ValidateDate(inputArray[3])) {
errors += "Invalid Effective Date" + '\\n';
}
if (ValidateDate(inputArray[4])) {
errors += "Invalid Cancel Date";
}
if (errors != "") {
errors = "Please check the following:" + '\\n' + errors;
alert(errors);
return false;
}
creates an alert that looks like this:
Upvotes: 1
Views: 1559
Reputation: 301
As others have you mentioned, you are escaping the first "\". One stylistic consideration you may want to make is to use an array that holds all of the error messages. Check if you have any errors and then join the array elements with the newline and alert the error messages.
Here is a working example that should get the point across.
Upvotes: 1
Reputation: 2019
\n is newline
by calling \\ you are escaping \ therefore asking browser to print \n not line break
Upvotes: 1