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) == '✔')
alert("symbol');
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.
is available two squares away from it (character code 254). Select the check mark you want. Click Insert.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With