PDA

View Full Version : removing items and repopulating items in selectbox


320rwekfpl
10-15-2002, 02:18 PM
I have this code that works in IE and Opera. What it does is remove a item from a number of selectboxes. I have a problem though... I cant make it work in Netscape/Mozilla(doesn't work at all in 4.xx). In IE and Opera the item is removed but in Netscape/Mozilla it gets replaced with the string [""] (it also adds this string to the other options). I cannot understand why, so... is there anyone outhere that have a clue?



function removeCart(uprice, qty, tprice){
if(document.c1.s1.selectedIndex < 1){
if(document.c1.s1.length != 0) {
var reArray1 = new Array();
var reArray2 = new Array();
var reArray3 = new Array();
var reArray4 = new Array();
var remv0 = new String();
var remv1 = new String();
x = document.c1.s1.selectedIndex;
document.c1.s2.options[x].selected = true;
document.c1.s3.options[x].selected = true;
document.c1.s4.options[x].selected = true;
x = document.c1.s1.selectedIndex;
y = document.c1.s2.selectedIndex;
z = document.c1.s3.selectedIndex;
v = document.c1.s4.selectedIndex;
for(i=0;i<document.c1.s1.options.length;i++){
reArray1[i] = document.c1.s1.options[i].value;
reArray2[i] = document.c1.s2.options[i].value;
reArray3[i] = document.c1.s3.options[i].value;
reArray4[i] = document.c1.s4.options[i].value;
}
reArray1[x] = "";
reArray2[y] = "";
reArray3[z] = "";
reArray4[v] = "";
reSumma = parseInt(document.c1.fSumma.value);
rePris = document.c1.s3.options.value;
reAntal = document.c1.s4.options.value;
document.c1.fSumma.value = parseInt(reSumma) -
parseInt(rePris) *
parseInt(reAntal);
document.c1.s1.options.length = 0;
document.c1.s2.options.length = 0;
document.c1.s3.options.length = 0;
document.c1.s4.options.length = 0;
var rep1 = new String();
var rep2 = new String();
var rep3 = new String();
var rep4 = new String();
var repa1 = new String();
var repa2 = new String();
var repa3 = new String();
var repa4 = new String();
rep1 = reArray1.toString();
rep2 = reArray2.toString();
rep3 = reArray3.toString();
rep4 = reArray4.toString();
if(rep1 != ""){
regExp1 = /\,+\,/g;
regExp2 = /\,/g;
repa1 = rep1.replace(regExp1,",");
repa2 = rep2.replace(regExp1,",");
repa3 = rep3.replace(regExp1,",");
repa4 = rep4.replace(regExp1,",");
var reArray6 = repa1.split(regExp2);
var reArray7 = repa2.split(regExp2);
var reArray8 = repa3.split(regExp2);
var reArray9 = repa4.split(regExp2);
for(k=0;k<reArray6.length;k++){
reOpt1 = new Option();
reOpt2 = new Option();
reOpt3 = new Option();
reOpt4 = new Option();
reOpt1.value = reArray6[k];
reOpt2.value = reArray7[k];
reOpt3.value = reArray8[k];
reOpt4.value = reArray9[k];
reOpt1.text = reArray6[k];
reOpt2.text = reArray7[k];
reOpt3.text = reArray8[k];
reOpt4.text = reArray9[k];
document.c1.s1[k] = reOpt1;
document.c1.s2[k] = reOpt2;
document.c1.s3[k] = reOpt3;
document.c1.s4[k] = reOpt4;
}
} else {
parent.articles.location = "grupper.html";
parent.cart.location = "cart.html";
}
} else {
describe("Varukorgen är tom...");
}
} else {
describe("Markera en artikel...");
}
}

320rwekfpl
10-16-2002, 09:44 AM
since nobody seems to know an answer it's very likely a bug in mozilla/netscape.

glenngv
10-16-2002, 10:12 AM
change:

for(k=0;k<reArray6.length;k++){
reOpt1 = new Option();
reOpt2 = new Option();
reOpt3 = new Option();
reOpt4 = new Option();
reOpt1.value = reArray6[k];
reOpt2.value = reArray7[k];
reOpt3.value = reArray8[k];
reOpt4.value = reArray9[k];
reOpt1.text = reArray6[k];
reOpt2.text = reArray7[k];
reOpt3.text = reArray8[k];
reOpt4.text = reArray9[k];
document.c1.s1[k] = reOpt1;
document.c1.s2[k] = reOpt2;
document.c1.s3[k] = reOpt3;
document.c1.s4[k] = reOpt4;
}


to:


for(k=0;k<reArray6.length;k++){
document.c1.s1.options[k] = new Option(reArray6[k],reArray6[k]);
document.c1.s2.options[k] = new Option(reArray7[k],reArray7[k]);
document.c1.s3.options[k] = new Option(reArray8[k],reArray8[k]);
document.c1.s4.options[k] = new Option(reArray9[k],reArray9[k]);
}