1

I'm trying to use JavaScript to set the value of an Input Text Box to this Emoji >> 🤔
But it didn't work as I expect it to.
I've tried several different format to express the Unicode but none of it works.
I've included the snippet that I've tried.

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

    <script>
      var myTextBox = document.createElement("input");
      document.body.appendChild( myTextBox );
      myTextBox.value = "&#129300";

      //	None of below will work:
      //	\u1F914
      //	\xF0\x9F\xA4\x94
      //	&#129300;
    </script>

    <p> &#129300; </p>

  </body>
</html>

Any idea on how to do this properly?

1
  • Check this link. You find find some solution for it Commented Aug 27, 2018 at 14:20

1 Answer 1

2

You need to convert it into a surrogate pair: "\uD83E\uDD14"

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

    <script>
      var myTextBox = document.createElement("input");
      document.body.appendChild( myTextBox );
      myTextBox.value = "\uD83E\uDD14";
    </script>

    <p> &#129300; </p>

  </body>
</html>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.