Double byte strings in javascript

T

Tharika

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
 
J

Jim Ley

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.
 
T

Tharika

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top