Q: Javascript Option object and HTML special characters


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Q: Javascript Option object and HTML special characters

  1. #1
    JT Guest

    Q: Javascript Option object and HTML special characters


    Does anybody know if the Option object in Javascript is unable to display
    HTML special characters like ", >, ™ ?

    Example:
    I would like to display the trademark character TM ( ™ ) by dynamically
    adding an option to a dropdown using the Option object. However, the ™
    gets displayed as is, without getting converted to the TM character.

    Try the sample code below. I have two options that are statically displayed
    with the special characters and they display fine. But when I try to add
    a dynamic option with the special character, it does not display properly.

    Any help/suggestions will be greately appreciated.


    Sample Code:
    <html>
    <script>

    function AddOption()
    {
    var l;
    l = document.joydeep.cbo.length;
    document.joydeep.cbo[l] = new Option("CompactFlash™",123,false,false);
    }
    </script>
    <body>
    <form name="joydeep">

    <SELECT name="cbo" onchange=AddOption()>
    <OPTION value="1">Trademarked Item™</OPTION>
    <OPTION value="2">Copyrighted Item&#174;</OPTION>
    </SELECT>

    </form>
    </body>
    </html>

  2. #2
    Michael Shutt Guest

    Re: Javascript Option object and HTML special characters

    According the WC3 specs, the correct character entity for trademark is
    either &trade; or ™

    Try this

    var strOption = "CompactFlash™"

    --
    Michael Shutt

    Please respond to newsgroup as I will not return direct emails.

    "JT" <joydeept@yahoo.com> wrote in message news:3b2e8f12$1@news.devx.com...
    >
    > Does anybody know if the Option object in Javascript is unable to display
    > HTML special characters like &quot;, &gt;, ™ ?
    >
    > Example:
    > I would like to display the trademark character TM ( ™ ) by

    dynamically
    > adding an option to a dropdown using the Option object. However, the


    > gets displayed as is, without getting converted to the TM character.
    >
    > Try the sample code below. I have two options that are statically

    displayed
    > with the special characters and they display fine. But when I try to add
    > a dynamic option with the special character, it does not display properly.
    >
    > Any help/suggestions will be greately appreciated.
    >
    >
    > Sample Code:
    > <html>
    > <script>
    >
    > function AddOption()
    > {
    > var l;
    > l = document.joydeep.cbo.length;
    > document.joydeep.cbo[l] = new

    Option("CompactFlash™",123,false,false);
    > }
    > </script>
    > <body>
    > <form name="joydeep">
    >
    > <SELECT name="cbo" onchange=AddOption()>
    > <OPTION value="1">Trademarked Item™</OPTION>
    > <OPTION value="2">Copyrighted Item&#174;</OPTION>
    > </SELECT>
    >
    > </form>
    > </body>
    > </html>




  3. #3
    Madusudanan R Guest

    Re: Q: Javascript Option object and HTML special characters


    Check this code snippet out.. This works
    function AddOption()
    {
    var l;
    l = document.joydeep.cbo.length;
    document.joydeep.cbo[l] = new Option("",123,false,false);
    document.joydeep.cbo[l].innerHTML = "CompactFlash™";
    }
    cheers,
    Madhu
    "JT" <joydeept@yahoo.com> wrote:
    >
    >Does anybody know if the Option object in Javascript is unable to display
    >HTML special characters like ", >, ™ ?
    >
    >Example:
    >I would like to display the trademark character TM ( ™ ) by dynamically
    >adding an option to a dropdown using the Option object. However, the ™
    >gets displayed as is, without getting converted to the TM character.
    >
    >Try the sample code below. I have two options that are statically displayed
    >with the special characters and they display fine. But when I try to add
    >a dynamic option with the special character, it does not display properly.
    >
    >Any help/suggestions will be greately appreciated.
    >
    >
    >Sample Code:
    ><html>
    ><script>
    >
    >function AddOption()
    >{
    > var l;
    > l = document.joydeep.cbo.length;
    > document.joydeep.cbo[l] = new Option("CompactFlash™",123,false,false);
    >}
    ></script>
    ><body>
    ><form name="joydeep">
    >
    ><SELECT name="cbo" onchange=AddOption()>
    ><OPTION value="1">Trademarked Item™</OPTION>
    ><OPTION value="2">Copyrighted Item®</OPTION>
    ></SELECT>
    >
    ></form>
    ></body>
    ></html>



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center