Tigerman55
Tigerman55

Reputation: 231

Funky Character getting generated with Javascript?

For some reason this character is getting generated in my HTML email when it is being sent: –. I have tried replacing it with nothing in my PHP using preg_replace('/–/', '', $var), but that is not working. For some reason when I get an email containing HTML this character shows up. I am guessing it is generated from this JavaScript in my code somehow:

$('.comments0').click(function(){
    $('.comments').val($('.comments').val() + 'Our warranties are:\nNew – 1 year\nRemanufactured - 6 months\nRepair - 6 months');
});

If it is not being generated with JavaScript, I am not sure how this character keeps getting created in the middle of my HTML. It gets generated right after New, just like this: New – 1 Year. I have no idea why this character is coming up randomly like this.

By the way, here is the HTML directly related to that JavaScript:

<form action="?AddToQuote" method="POST" id="myForm" name="myForm">
<input type="checkbox" name="comments[0]" class="comments0" id="comments0" /><label>6 Months Warranty</label>
<textarea cols="75" rows="6" name="comments" class="comments" id="comments"><?php if(isset($_SESSION['comments'])) { echo $_SESSION['comments']; } ?></textarea>
</form>

Upvotes: 2

Views: 109

Answers (3)

suff trek
suff trek

Reputation: 39777

Apparently the characters in your message were copied/pasted from somewhere else. If you delete them and manually retype directly in the JS source that should do the trick.

Upvotes: 1

DevlshOne
DevlshOne

Reputation: 8457

Be sure that your text editor / IDE is set to save files as UTF-8 with NO BOM.

Also, be sure you are using <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> in your page <head> and setting your emails up as UTF-8.

Upvotes: 0

Ry-
Ry-

Reputation: 224942

This is an en dash:

New 1 year

If you don’t serve the script with the same encoding as it was written in, there will be errors. So make sure it’s saved as UTF-8 and serve it as UTF-8. If the JavaScript is part of your HTML, add this at the top of the <head> (HTML5):

<meta charset="utf-8">

You can test it:

$ echo '–' > test.html
$ firefox test.html
(– shows up in a browser)

Upvotes: 1

Related Questions