I have a page with a select box. The select box is defaulted to index 2, and it's corresponding div. When the user makes a selection from the select box, the previous selection's div should disappear, and the new selection's div should display.
However, the new div is appearing below the old div, and the old div is still visible.
I use an onChange event to trigger the js that should set the display property for the selected element to block and all of the other elements to none. Here's some of the relevent code. Any ideas appreciated.
However, the new div is appearing below the old div, and the old div is still visible.
I use an onChange event to trigger the js that should set the display property for the selected element to block and all of the other elements to none. Here's some of the relevent code. Any ideas appreciated.
Code:
<STYLE type="text/css">
<!--
#pending_id { position: relative;
display: block;}
#accepted_id { position: relative;
display: none; }
#declined_id { position: relative;
display: none; }
#rescinded_id { position: relative;
display: none; }
-->
</STYLE>
<script language="JavaScript">
// function showDiv()
// this function takes the id of a div
// and calls the other functions required
// to show that div
//
function showDiv(div_id)
{
var style_sheet = getStyleObject(div_id);
if (style_sheet)
{
hideAll();
changeObjectVisibility(div_id,"block");
}
else
{
alert("sorry, this only works in browsers that do Dynamic HTML");
}
}
// function hideAll()
// hides a bunch of divs
//
function hideAll()
{
changeObjectVisibility("pending_ID","none");
changeObjectVisibility("accepted_ID","none");
changeObjectVisibility("declined_ID","none");
changeObjectVisibility("rescinded_ID","none");
}
// function getStyleObject(string) -> returns style object
// given a string containing the id of an object
// the function returns the stylesheet of that object
// or false if it can't find a stylesheet. Handles
// cross-browser compatibility issues.
//
function getStyleObject(objectId) {
if(document.getElementById && document.getElementById(objectId)) {
return document.getElementById(objectId).style;
}
else if (document.all && document.all(objectId)) {
return document.all(objectId).style;
}
else if (document.layers && document.layers[objectId]) {
return document.layers[objectId];
} else {
return false;
}
}
function changeObjectVisibility(objectId, newVisibility) {
// first get a reference to the cross-browser style object
// and make sure the object exists
var styleObject = getStyleObject(objectId);
if(styleObject) {
styleObject.display = newVisibility;
return true;
} else {
// we couldn't find the object, so we can't change its visibility
return false;
}
}
</script>