Forum Moderators: open
I'm not sure if this is the place to post this question as it relates to JavaScript. But I'll give it a go anyway.
I've been trying to use getElementById to retrieve the id of a drop down list box (e.g. select name="items[]" id="itms") This works fine with most browsers but it doesn't work for NN4 (surprise surprise!).
I am looking at document.layers but am unsure as how to retrieve the id this way. Any advice would be appreciated.
Regards,
Chris.
if (document.getElementById) {
document.getElementById('hidepage').style.visibility = 'hidden';
}
else {
if (document.layers) { // Netscape 4
document.hidepage.visibility = 'hidden';
}
else { // IE 4
document.all.hidepage.style.visibility = 'hidden';
}
regards,
Mark
I actually need to retrieve the value of the id.
I have a drop down list box with an array for a name. To access this easier I have given it an Id. Using getElementById I can retrieve the value but can't with document.layers.
E.G. Drop Down List Box.
<select name="array_name[]" id="totals" onchange="add_totals()">
I don't know if document.layers can be used for this purpose. If not, any other suggestions? (I have to use array_name[]).
Regards,
Chris.
if (document.getElementById) { // standards compliant
theElement = document.getElementById("animated");
maxLeft = wWidth - parseInt(theElement.style.width);
maxTop = wHeight - parseInt(theElement.style.height);
} else if ((document.all) && (!document.getElementById)) { // ie4
theElement = document.all.animated;
maxLeft = wWidth - parseInt(theElement.style.width);
maxTop = wHeight - parseInt(theElement.style.height);
} else if (document.layers) { // ns4
wWidth = window.innerWidth;
wHeight = window.innerHeight;
theElement = document.layers["animated"];
maxLeft = wWidth - parseInt(theElement.document.width);
maxTop = wHeight - parseInt(theElement.document.height);
} // endif ns4/document.layers
Thanks for your response but I don't think I've made myself clear. What I need is to retrieve the value of the list. That is what the user selected from the list. As I said above the drop down has an array name and an id. As you know using getElementById(id).value doesn't work on NN4. The question is, how else can I retrieve what the user has selected?
I have also tried "document.formName.elements[elementId].value" but again this won't work on NN4.
Any advice is greatly appreciated.
Cheers,
Chris.
<select name="array_name[]" id="totals" onchange="add_totals(this.form,'array_name[]')">
function add_totals(theForm,selectList) {
// ...(existing JavaScript to where you need value from list)
theValue = getSelectValue(theForm,selectList);
// ...(existing JavaScript)
} // end add_totalsfunction getSelectValue(form,listName) {
return form[listName].options[form[listName].selectedIndex].value;
}