Double byte strings in javascript

Discussion in 'Javascript' started by Tharika, Sep 12, 2004.

  1. Tharika

    Tharika Guest

    Hi,

    I have a web page with a <select> listbox that contains both English
    strings and Kanji-character strings in the options. The charset on the
    page is set to UTF-8 and on load of the page, both language strings
    are displayed correctly.

    I have a javascript function where the user can select a list item and
    click on a button to move it up in the sequence or down, basically to
    let them set an order among the list items. The logic used is a simple
    swap of two values, with the selected item value stored in a temp.
    variable, the selected item replaced with the next item in the list
    and the next item replaced with the temp. variable. Below is the code
    for moving up the item,

    function GoUp()
    {
    var i, j, s, seltext, selval, selcol

    if (frmModCon.lstConSeq.length > 0)
    {
    j = frmModCon.lstConSeq.selectedIndex;
    if (j != -1)
    {
    seltext = frmModCon.lstConSeq(j).innerText;
    selval = frmModCon.lstConSeq(j).value;
    selcol = frmModCon.lstConSeq(j).style.color;
    s = parseInt(frmModCon.lstConSeq.length) - 1;

    if (j!=0)
    {
    i = parseInt(j) - 1;

    frmModCon.lstConSeq.item(j).selected = false;
    frmModCon.lstConSeq(j).innerText =
    frmModCon.lstConSeq(i).innerText;
    frmModCon.lstConSeq(j).value = frmModCon.lstConSeq(i).value;
    frmModCon.lstConSeq(j).style.color =
    frmModCon.lstConSeq(i).style.color;

    frmModCon.lstConSeq.item(i).selected = true;
    frmModCon.lstConSeq(i).innerText = seltext;
    frmModCon.lstConSeq(i).value = selval;
    frmModCon.lstConSeq(i).style.color = selcol;
    }
    }
    }
    }

    I notice that as long as one Kanji-character list item is swapped with
    another Kanji-character list item, the display is still fine. However,
    when an English string and a Kanji-character string are swapped, the
    Kanji-character display is lost and starts showing boxes in place of
    the characters.

    What am I doing wrong? Any help will be appreciated as this issue is
    holding up entire application deployment.

    Thanks........... Tharika
    Tharika, Sep 12, 2004
    #1
    1. Advertising

  2. Tharika

    Jim Ley Guest

    On 12 Sep 2004 11:02:21 -0700, (Tharika) wrote:
    >I notice that as long as one Kanji-character list item is swapped with
    >another Kanji-character list item, the display is still fine. However,
    >when an English string and a Kanji-character string are swapped, the
    >Kanji-character display is lost and starts showing boxes in place of
    >the characters.


    At a guess you're running into a bug with the SELECT control, it's
    double-byte support is probably dodgy - you're not doing anything
    wrong as I can see it, so you're going to have to look at workarounds,
    rather than swapping innerText's maybe swap .text or create new
    elements each time, or... who knows you'll probably have to try it
    I'm afraid. Your code should IMO just work, but I'm not surprised the
    native select control doesn't do this too well.

    Jim.
    Jim Ley, Sep 13, 2004
    #2
    1. Advertising

  3. Tharika

    Tharika Guest

    Hi Jim,

    Your suggestion turned out to be very beneficial. I replaced the
    innerText in the code with text and it worked :) I am still trying to
    figure out the difference in the properties.

    Thanks a ton!..... Tharika


    > At a guess you're running into a bug with the SELECT control, it's
    > double-byte support is probably dodgy - you're not doing anything
    > wrong as I can see it, so you're going to have to look at workarounds,
    > rather than swapping innerText's maybe swap .text or create new
    > elements each time, or... who knows you'll probably have to try it
    > I'm afraid. Your code should IMO just work, but I'm not surprised the
    > native select control doesn't do this too well.
    >
    > Jim.
    Tharika, Sep 13, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas
    Replies:
    1
    Views:
    845
    Jonathan Bromley
    May 4, 2004
  2. Bharat Bhushan

    Appending byte[] to another byte[] array

    Bharat Bhushan, Aug 5, 2003, in forum: Java
    Replies:
    15
    Views:
    40,241
    Roedy Green
    Aug 5, 2003
  3. Sydex
    Replies:
    12
    Views:
    6,483
    Victor Bazarov
    Feb 17, 2005
  4. jeko

    reading a double var byte per byte

    jeko, Jan 18, 2005, in forum: C Programming
    Replies:
    12
    Views:
    548
  5. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    755
    Malcolm
    Jun 24, 2006
Loading...

Share This Page