/    Sign up×
Community /Pin to ProfileBookmark

Error: document.getElementById(img) has no properties

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!

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@JPnycDec 19.2005 — Not without seeing the HTML too.
Copy linkTweet thisAlerts:
@pcofauthorDec 19.2005 — [URL=http://www.rockhour.com.br/preview/]http://www.rockhour.com.br/preview/[/URL]

Thanks.
Copy linkTweet thisAlerts:
@JPnycDec 19.2005 — Could you please post the relevant HTML here? I hate sites that play music at me.
Copy linkTweet thisAlerts:
@pcofauthorDec 19.2005 — 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:

[code=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[/code]


Thanks for your help!
Copy linkTweet thisAlerts:
@JPnycDec 19.2005 — 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')
Copy linkTweet thisAlerts:
@JPnycDec 19.2005 — Alternatively you can also pass the ID in the function call but you don't appear to be doing that either
Copy linkTweet thisAlerts:
@pcofauthorDec 19.2005 — 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.
×

Success!

Help @pcof spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...