PDA

View Full Version : [NETSCAPE] move to a select box in a different frame


320rwekfpl
09-19-2002, 02:23 PM
I've been trying for quite a while now to write a script that moves a value to a selectbox in a different frame.
I've come up with a way that works in IE and Opera, but I just cannot make it work on Netscape(neither 4 or 6 or 7). So now I wonder, is there any way to make this work in Netscape;

//starts here

function addToCart(a, b, c, qty)
{
if(document.frames["cart"].c1.s1.length == 0)
{
var i = document.frames["cart"].c1.s1.options.length++;
var j = document.frames["cart"].c1.s2.options.length++;
var k = document.frames["cart"].c1.s3.options.length++;
var l = document.frames["cart"].c1.s4.options.length++;
document.frames["cart"].c1.s1.options[i].value = a;
document.frames["cart"].c1.s1.options[i].text = a;
document.frames["cart"].c1.s2.options[j].value = b;
document.frames["cart"].c1.s2.options[j].text = b;
document.frames["cart"].c1.s3.options[k].value = c;
document.frames["cart"].c1.s3.options[k].text = c;
document.frames["cart"].c1.s4.options[l].value = qty;
document.frames["cart"].c1.s4.options[l].text = qty;
}
else
{
if(a == document.frames["cart"].c1.s1.options.value)
{
var x = document.frames["cart"].c1.s1.selectedIndex;
var y = document.frames["cart"].c1.s4.options[x].value;
z = parseInt(y) + parseInt(qty);
document.frames["cart"].c1.s4.options[x].value = z;
document.frames["cart"].c1.s4.options[x].text = z;
}
else
{
var i = document.frames["cart"].c1.s1.options.length++;
var j = document.frames["cart"].c1.s2.options.length++;
var k = document.frames["cart"].c1.s3.options.length++;
var l = document.frames["cart"].c1.s4.options.length++;
document.frames["cart"].c1.s1.options[i].value = a;
document.frames["cart"].c1.s1.options[i].text = a;
document.frames["cart"].c1.s2.options[j].value = b;
document.frames["cart"].c1.s2.options[j].text = b;
document.frames["cart"].c1.s3.options[k].value = c;
document.frames["cart"].c1.s3.options[k].text = c;
document.frames["cart"].c1.s4.options[l].value = qty;
document.frames["cart"].c1.s4.options[l].text = qty;
}
}
summaValue = document.frames["cart"].c1.fSumma.value;
document.frames["cart"].c1.fSumma.value = parseInt(summaValue)+parseInt(c)*parseInt(qty);
}

// Ends here

adios
09-19-2002, 04:22 PM
Surprising that works in IE, although - not that surprising. The frames[] collection, with its objects representing frames/iframes, is a property of the window, not the document. You can generally reference them as simply frames[frame_name] or frames[index], leaving out the window. reference.

Also - you will need to reference the document when referring to the form:

var i = frames["cart"].document.c1.s1.options.length++;

http://www.webreference.com/js/column36/index.html

320rwekfpl
09-20-2002, 06:54 AM
Actually... I dont know why I never thought of that. It's so obvious... Thanks for the help!