PDA

View Full Version : can someone tell me the right syntax?


kamarthi7
05-07-2003, 10:12 AM
hello friend,

the below sample code is working fine with all the browsers, basically the below code tries to hide or display the contents on click event.

well on toggle I am even trying to change the image which is in the div tag. it works fine in IE+, NN6+, but it is not working in the NN4.x.
I found in some books for NN4.x. to change the contents in a layer it should be like

document.layers['layerName'].document.images['imgName'].src="img.gif"

Is this syntax correct, or is there any modification has to be done. please help me.


<HTML><HEAD><TITLE>TITLE-SUBMENU</TITLE>
<STYLE>
.title {
FONT-SIZE: 12px; Z-INDEX: 10; LEFT: 10px; WIDTH: 590px; COLOR: #000066; FONT-FAMILY: Arial, Helvetica, sans-serif; POSITION: absolute; HEIGHT: 20px
}
.submenu {
FONT-SIZE: 12px; LEFT: 30px; VISIBILITY: hidden; WIDTH: 560px; FONT-FAMILY: Arial, Helvetica, sans-serif; POSITION: absolute
}
</STYLE>

<BODY>
<DIV class=title id=title1 style="TOP: 100px;">
<A href="javascript:void(null);" onclick="toggle();">
<img src="sand.gif" id=pic1 border="0">
1ST TITLE</A>
</DIV>
<div class=submenu id=submenu1 style="top:120px;">some text here</div>

<script language=javascript>
function toggle()
{
if(document.layers)
{
if(document.layers['submenu1'].visibility=="show")
{
document.layers['submenu1'].visibility="hide";
document.layers['submenu1'].document.images['pic1'].src="sand.gif"
}
else
{
document.layers['submenu1'].visibility="show";
document.layers['submenu1'].document.images['pic1'].src="purple.gif"
}
}
if(document.getElementById)
{
if(document.getElementById('submenu1').style.visibility=="visible")
{
document.getElementById('submenu1').style.visibility="hidden";
document.getElementById('pic1').src="sand.gif";
}
else
{
document.getElementById('submenu1').style.visibility="visible";
document.getElementById('pic1').src="purple.gif";
}
}

}

</script>
</BODY>
</HTML>


hope this code is very simple to understand......:thumbsup:

RoyW
05-07-2003, 02:42 PM
Well, the syntax is correct but your image is in a DIV called 'title1'


document.layers['title1'].document.images['pic1'].src="sand.gif"


<edit>
Also, for it to work in NS4 you need to give the image a name.
<img id="pic1" name="pic1"....>
</edit>

kamarthi7
05-07-2003, 03:49 PM
but even with the name given for the image is not working.

kamarthi7
05-07-2003, 03:55 PM
hai,

sorry, its working. thanks a lot friend..