Technosavia
Technosavia

Reputation: 85

HTML special characters are not showing properly in js

I am developing a web application using PHP,Smarty for a french client. I am facing a problem in java script alert and confirm boxes. How can I use HTML special characters in javascript message boxes. This is my code

<script type="text/javascript">
    function delConfirm(key){

        if(confirm('&Ecirc;tes vous certain de vouloir supprimer ce client ?')){
            window.location = "deleteClient.php?e="+key;
        }

    }
</script>

This is the page source of the first part of the page. Please take a look at the encoding section too,

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="Sunil">

Upvotes: 2

Views: 7603

Answers (2)

T.J. Crowder
T.J. Crowder

Reputation: 1074335

That's correct, because confirm doesn't accept HTML. You can use unicode escape sequence in JavaScript, though. You can look up Unicode code point values here. The equivalent of &Ecirc; is U+00CA (it's on this chart), so:

if(confirm('\u00CAtes vous certain de vouloir supprimer ce client ?')){
    window.location = "deleteClient.php?e="+key;
}

Alternately, ensure that your file is correctly encoded (in UTF-8 for example), that your editor understands files encoded in that way, and that the file is served correctly (the server tells the browser it's UTF-8), maybe even throw in a meta charset="xxx" tag in the header for luck, and you can just type the French characters directly into the file.

Upvotes: 7

Jeow Li Huan
Jeow Li Huan

Reputation: 3796

Use this instead

<script type="text/javascript">
    function delConfirm(key){

        if(confirm('\u00CAtes vous certain de vouloir supprimer ce client ?')){
            window.location = "deleteClient.php?e="+key;
        }

    }
</script>

Upvotes: 1

Related Questions