Navoneel Talukdar
Navoneel Talukdar

Reputation: 4588

Adding line break or new line in javascript

This may be a pretty noob question but I am not able to figure out after repeated trial and error.

I have a string getting returned from wcf service like this

TVA Rate cannot be less that 1 or greater than 49.----- L'âge du permis doit être inférieur à l'âge du conducteur moins 17 ans

What I want is in my ajax success when I get this message I would replace the ----- portion with a new line so that these two lines get displayed on separate lines.

What I have done for this

Try 1

if (response.data.Messages.Messages != null) {                        
    $scope.warningMsg = response.data.Messages.Messages[0].EventSource.replace("------", "</br>");
}

Try 2

if (response.data.Messages.Messages != null) {                        
    $scope.warningMsg = response.data.Messages.Messages[0].EventSource.replace("------", "\n");
}

And the WCF message is getting constructed in this way

if (data.DriverData.age - data.DriverData.permitage < 18)
{
    isValid = false;
    validationMsg.Append("------");
    validationMsg.Append("L'âge du permis doit être inférieur à l'âge du conducteur moins 17 ans.");               
}
if (data.RCData.YearsProvenWithAttest > 5)
{
    isValid = false;
    validationMsg.Append("------");
    validationMsg.Append("YearsProvenWithAttest MAX 5.");               
}

No matter I see the result in single sentence always.

Can someone please tell me what silly thing I am doing? Thanks.

Upvotes: 2

Views: 99

Answers (2)

Busch4Al
Busch4Al

Reputation: 53

What are you doing with the message? If you're appending it to .innerText, you'll see exactly the characters you add. Use .innerHTML to see the html.

Upvotes: 1

jasonwarford
jasonwarford

Reputation: 746

You need to change </br> to <br />

That should give you the line breaks where you need them.

Upvotes: 1

Related Questions