Problem with special character "ç" in javascript

2

I have a switch case to check the month and I had to add a hexcode for the month of March not to have problem with the character "ç".

The March string was going like this: Mar o

One of the ways to solve the problem would be to put the tag in the html, however the code is pure javascript and I can not set that tag.

I put the hexcode, it worked perfectly, but I'd like to know what the best way to do it is.

    
asked by anonymous 10.11.2017 / 10:46

3 answers

2

You can use a UNICODE \u fault escape sequence to represent ç and Ç :

\u00e7 is equivalent to ç (lowercase)

\u00c7 is equivalent to Ç (uppercase)

For example:

alert('mar\u00e7o'); 
alert('MAR\u00c7O'); 
      
10.11.2017 / 11:10
0

If you are displaying things that are not brought from the database you can use this tag in your HTML file, <meta http-equiv="content-type" content="text/html; charset=UTF-8"> Or if the case is to bring database data with accentuation you will have to create a function for this in order to exchange values that may appear this way

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<form method="POST" name="alimento">
   <select>
      <option selected>Feij&atilde;o</option>
      <option>Pa&ccedil;oca</option>
   </select>
</form>

<?php
   $alimento = utf8_decode(($_POST['alimento']));
   echo $alimento;
?>

As a result of select = > Paçoca e Feijão

    
10.11.2017 / 13:09
-1

If you do not want to use the hexcode you can try using our function to encode the "ç" ... I do not think it's feasible whenever a special character has to look for its hexcode:

UTF8_encode

    
10.11.2017 / 12:59