ether
ether

Reputation: 937

Javascript encoding

I have a javascript file linked externally. And inside that javascript, I have this function:

function getMonthNumber(monthName){
monthName = monthName.toLowerCase();
if(monthName == 'janvier'){
    return "01";
}else if(monthName == 'février'){
    return "02";
}else if(monthName == 'mars'){
    return "03";
}else if(monthName == 'avril'){
    return "04";
}else if(monthName == 'mai'){
    return "05";
}else if(monthName == 'juin'){
    return "06";
}else if(monthName == 'juillet'){
    return "07";
}else if(monthName == 'août'){
    return "08";
}else if(monthName == 'septembre'){
    return "09";
}else if(monthName == 'octobre'){
    return "10";
}else if(monthName == 'novembre'){
    return "11";
}else if(monthName == 'décembre'){
    return "12";
}

}

But, when I read it in Firebug, I see:

function getMonthNumber(monthName){
    monthName = monthName.toLowerCase();
    if(monthName == 'janvier'){
        return "01";
    }else if(monthName == 'février'){
        return "02";
    }else if(monthName == 'mars'){
        return "03";
    }else if(monthName == 'avril'){
        return "04";
    }else if(monthName == 'mai'){
        return "05";
    }else if(monthName == 'juin'){
        return "06";
    }else if(monthName == 'juillet'){
        return "07";
    }else if(monthName == 'août'){
        return "08";
    }else if(monthName == 'septembre'){
        return "09";
    }else if(monthName == 'octobre'){
        return "10";
    }else if(monthName == 'novembre'){
        return "11";
    }else if(monthName == 'décembre'){
        return "12";
}
} 

So that, basically all the accents were encoded.

As far as I found on the net, passing the charset to the script should fix that, but even though I tried passing charset="utf8" or charset="ISO-8859-1", none seems to work.

I'm not sure how to fix that. Any ideas?

Upvotes: 1

Views: 2762

Answers (4)

Jim
Jim

Reputation: 11

You can change your Dreamweaver preference to save files in Unicode. This will allow your special characters to appear correctly in a UTF-8 encoded document.

See Set Fonts preferences for documents in Dreamweaver.

Upvotes: 1

ether
ether

Reputation: 937

As stated by JKirchartz and Šime Vidas, the answer was to make sure to save the file in the right charset. Basically, dreamweaver was not saving it the good charset, but Eclipse does. So I removed the charset attribute on the script and just saved it in the good charset and now it works.

Upvotes: 1

JP Richardson
JP Richardson

Reputation: 39385

To expand on Jukka's answer, make sure that if your doctype is HTML 5, set your meta charset like so:

<head>
  <meta charset="utf-8">
</head>

Upvotes: 0

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201538

Make the server specify, in HTTP headers, the encoding with charset=utf-8 (with the hyphen in the value; utf8 is not correct). If problems remain, post a URL; it is possible that for some reason, the HTTP header is not sent as intended.

Upvotes: 1

Related Questions