Double byte strings in javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tharika

    #1

    Double byte strings in javascript

    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.lstC onSeq.length > 0)
    {
    j = frmModCon.lstCo nSeq.selectedIn dex;
    if (j != -1)
    {
    seltext = frmModCon.lstCo nSeq(j).innerTe xt;
    selval = frmModCon.lstCo nSeq(j).value;
    selcol = frmModCon.lstCo nSeq(j).style.c olor;
    s = parseInt(frmMod Con.lstConSeq.l ength) - 1;

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

    frmModCon.lstCo nSeq.item(j).se lected = false;
    frmModCon.lstCo nSeq(j).innerTe xt =
    frmModCon.lstCo nSeq(i).innerTe xt;
    frmModCon.lstCo nSeq(j).value = frmModCon.lstCo nSeq(i).value;
    frmModCon.lstCo nSeq(j).style.c olor =
    frmModCon.lstCo nSeq(i).style.c olor;

    frmModCon.lstCo nSeq.item(i).se lected = true;
    frmModCon.lstCo nSeq(i).innerTe xt = seltext;
    frmModCon.lstCo nSeq(i).value = selval;
    frmModCon.lstCo nSeq(i).style.c olor = 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
  • Jim Ley

    #2
    Re: Double byte strings in javascript

    On 12 Sep 2004 11:02:21 -0700, tharika@gmail.c om (Tharika) wrote:[color=blue]
    >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.[/color]

    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.

    Comment

    • Tharika

      #3
      Re: Double byte strings in javascript

      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

      [color=blue]
      > 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.[/color]

      Comment

      Working...