This function works in IE but not Netscape or Mozilla. Doesn't seem to be evaluating getElementById in Netscape or Mozilla. The function getStyleObject(objectId) returns false for Net. and Moz.
I have several div's that will show/hide according to the option box selection.
Here's a snippet of relevent code.
I have several div's that will show/hide according to the option box selection.
Here's a snippet of relevent code.
Code:
<STYLE type="text/css">
<!--
#pending_id { position: relative;
display: block;}
#accepted_id { position: relative;
display: none; }
-->
</STYLE>
<Script Language="JavaScript">
function changeDiv(OfferStatusName, element)
{
if (StatusName == "Status")
{
if (element == 0)
{
showDiv("accepted_ID")
}
else if (element == 1)
{
showDiv('pending_ID')
}
}
}
// function showDiv()
// takes the id of a div and
// calls the other functions required
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) {
alert(objectId); //I'm getting the correct value here
if(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>
<SELECT class="dropdown" name="Status" onChange="changeDiv(document.Form.Status.name, document.Form.OfferStatus2.selectedIndex)"></SELECT>
<dive id="pending_id">
some html
</div>
<dive id="accepted_id">
some html
</div>