Click to See Complete Forum and Search --> : Error: document.getElementById(img) has no properties


pcof
12-18-2005, 06:50 PM
Hi Folks!
This is my first post in this forum so excuse me any incovenience.

I am getting this error with firefox with the script below:
Error: document.getElementById(img) has no properties

<---------------
function MostrarMenu(div)
{
EsconderTudo();
menu = "Menu" + div;
img = "Img" + div;
img_over = "images/btn_" + div + "_over.gif"
document.getElementById(img).src = img_over;
document.getElementById(menu).style.display='';
}
function EsconderMenu(div)
{
menu = "Menu" + div;
img = "Img" + div;
img_out = "images/btn_" + div + "_out.gif"
document.getElementById(img).src = img_out;
document.getElementById(menu).style.display='none';
}
function EsconderTudo()
{
EsconderMenu("festival");
EsconderMenu("galeria");
}
------------>

If anyone may help me. Thanks!

JPnyc
12-18-2005, 06:52 PM
Not without seeing the HTML too.

pcof
12-18-2005, 06:57 PM
http://www.rockhour.com.br/preview/

Thanks.

JPnyc
12-18-2005, 07:08 PM
Could you please post the relevant HTML here? I hate sites that play music at me.

pcof
12-18-2005, 07:18 PM
Sorry.... hehehe but this is just a preview!

We intend to play the songs only if the users click on PLAY button.

Here is the HTML:

<td><a href="home.html" onmouseover="EsconderTudo();MM_swapImage('home','','images/btn_home_over.gif',1);" onmouseout="MM_swapImgRestore()" onclick="return loadIframe('ifrm', this.href)"><img src="images/btn_home_out.gif" width="80" height="34" border="0" id="imghome" name="home" /></a></td>
<td><a href="#" onmouseover="MostrarMenu('festival')"><img src="images/btn_festival_out.gif" width="93" height="34" border="0" id="imgfestival" /></a></td>
<td><a href="#" onmouseover="EsconderTudo();MM_swapImage('bandas','','images/btn_bandas_over.gif',1);" onmouseout="MM_swapImgRestore()"><img src="images/btn_bandas_out.gif" width="86" height="34" border="0" id="imgbandas" name="bandas" /></a></td>
<td><a href="#" onmouseover="MostrarMenu('galeria')"><img src="images/btn_galeria_out.gif" width="86" height="34" border="0" id="imggaleria" /></a></td>
<td width="124">&nbsp;</td>
<td><a href="#"><img src="images/btn_blog_out.gif" name="blog" width="52" height="34" border="0" id="blog" onmouseover="EsconderTudo();MM_swapImage('blog','','images/btn_blog_over.gif',1);" onmouseout="MM_swapImgRestore()" /></a></td>
<td><a href="#"><img src="images/btn_imprensa_out.gif" name="imprensa" width="99" height="34" border="0" id="imprensa" onmouseover="EsconderTudo();MM_swapImage('imprensa','','images/btn_imprensa_over.gif',1);" onmouseout="MM_swapImgRestore()" /></a></td>
<td><a href="#"><img src="images/btn_parceiros_out.gif" name="parceiros" width="103" height="34" border="0" id="parceiros" onmouseover="EsconderTudo();MM_swapImage('parceiros','','images/btn_parceiros_over.gif',1);" onmouseout="MM_swapImgRestore()" /></a></td>
<td><a href="#"><img src="images/btn_contato_out.gif" name="contato" width="92" height="34" border="0" id="contato" onmouseover="EsconderTudo();MM_swapImage('contato','','images/btn_contato_over.gif',1);" onmouseout="MM_swapImgRestore()" /></a></td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" height="28">
<tr>
<td><table border="0" cellspacing="0" cellpadding="0" id="menufestival" style="display:none;">
<tr>
<td><a href="festival/programacao/index.html" onmouseover="MM_swapImage('prog','','images/btn_programacao_over.gif',1)" onmouseout="MM_swapImgRestore()" onclick="return loadIframe('ifrm', this.href)"><img src="images/btn_programacao_out.gif" name="prog" width="113" height="26" border="0" id="prog" /></a></td>
<td><a href="festival/ed_anterior/index.html" target="conteudo" onclick="return loadIframe('ifrm', this.href)" onmouseover="MM_swapImage('anterior','','images/btn_anterior_over.gif',1)" onmouseout="MM_swapImgRestore()"><img src="images/btn_anterior_out.gif" name="anterior" width="118" height="26" border="0" id="anterior" /></a></td>
<td><a href="festival/faq/index.html" onmouseover="MM_swapImage('faq','','images/btn_faq_over.gif',1)" onclick="return loadIframe('ifrm', this.href)" onmouseout="MM_swapImgRestore()"><img src="images/btn_faq_out.gif" name="faq" width="50" height="26" border="0" id="faq" /></a></td

Thanks for your help!

JPnyc
12-18-2005, 07:34 PM
Well you have no elements with an ID of either img, or menu. The getElementById method requires that some element have the ID assigned to it that you pass to the function. Also, the id must be in quotes; getElementById('id')

JPnyc
12-18-2005, 07:35 PM
Alternatively you can also pass the ID in the function call but you don't appear to be doing that either

pcof
12-19-2005, 03:51 AM
I didn't get the point.

I put the id inside quotes but it didn't work. I am still getting an error message inside firefox. In IE everything is working fine.

Another doubt:
I am using a javascript to resize automatically an iframe. Everything is perfect but inside this iframe I would like to put another iframe and resize it automatically again. The script works but only if I refresh the page.

Thanks again.