Problem with special character "ç" in javascript

Asked

Viewed 4,284 times

2

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

The March string was like this: Mar o

One of the ways to solve the problem would be putting the tag in html, but the code is pure javascript and I can’t set this tag.

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

  • But are you displaying this value in HTML or console? If it’s in HTML, there’s no reason not to tag charset.

3 answers

2


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

\u00e7 is equivalent to ç (minuscule)

\u00c7 is equivalent to Ç (capital)

For example:

alert('mar\u00e7o'); 
alert('MAR\u00c7O'); 

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 data from the database accentuated will have to create a function for it 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

  • I’ll fix the code

-1

If you do not want to use the hexcode you can try using this function to give Find in the "ç"... I do not think it is feasible whenever you have a special character to have to look for its hexcode:

Utf8_encode

Browser other questions tagged

You are not signed in. Login or sign up in order to post.