Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing unicode code tick mark values

I'm using Unicode value '✔' to display a tick mark in text area.

Now I need to fetch the value in text area and need to check whether symbol is present in that?

When I'm fetching the text area value I'm getting a checkbox without tick like symbol instead of tick symbol.

How can I compare this Unicode value is exist or not?

// Not working.
if( document.getElementById('location').value.charAt(0) == '&#10004')
    alert("symbol');
like image 445
Rosh Avatar asked Feb 13 '12 07:02

Rosh


People also ask

How do I type a check mark in Unicode?

In the web page's HTML source code, add one of the following Unicode HTML entities, depending on the type of check mark you want to insert. ☑ - inserts the " ☑ " symbol. ✓ - adds the " ✓ " symbol. ✔ - inserts the " ✔ " symbol.

What is the character code for a checkmark?

is available two squares away from it (character code 254). Select the check mark you want. Click Insert.


1 Answers

Your problem is that ✔ is an HTML entity that represents in HTML but it is just a string in JavaScript. In JavaScript you'd want '✔' (the raw character) or '\u2714':

if(document.getElementById('location').value.charAt(0) == '\u2714')
    alert("symbol");
else
    alert("not there");
​

Demo: http://jsfiddle.net/ambiguous/WCdCg/

The HTML &#....; notation uses decimal numbers, the JavaScript '\u....' notation uses hexadecimal. Converting 10004 to hexadecimal yields 2714. You can also use &#x....; in HTML if you want to use hexadecimal there as well, for example ✔ is ✔. Using just hexadecimal is probably easier than dealing with the base conversions.

like image 85
mu is too short Avatar answered Oct 04 '22 06:10

mu is too short