Jump to content

Javascript does not work in Firefox


Brav

Recommended Posts

JS does not work in Firefox, but it works perfectly in all other browsers (IE, Opera, Chrome, Safari). Can someone tell me what seems to be the problem? Her is the code:

<script type='text/javascript'>function hideShow(el_id){	var el=document.getElementById(el_id);	if(el_id.style.display!="none"){	  el_id.style.display="none";	}else{	  el_id.style.display="";	}  }</script>

and code where i call on the function:

><a href="#" onclick="hideShow(rowA);">Hide/Show Row A</a>

Link to comment
Share on other sites

I believe we solved that in your other post. :)

One other thing. Your function is a little off too. You have:
function hideShow(el_id){  var el=document.getElementById(el_id);  if(el_id.style.display!="none"){	el_id.style.display="none";  }else{	el_id.style.display="";  }}

el is the reference to the element, el_id is the id used to get the reference. You should be access the properties of the element like this:el.style.display

Link to comment
Share on other sites

Javascript works just fine in Firefox. You're telling the browser to set the style.display property on a string, not an element. I would seriously doubt that code would work the way you want it to in any browser, in all browsers el_id will be a string ID of an element, not an actual element. Any browser I'm aware of will give an undefined property error on that if statement line.

Link to comment
Share on other sites

and code where i call on the function:
><a href="#" onclick="hideShow(rowA);">Hide/Show Row A</a>

Error console says rowA is not defined - Line 1 - and this is highlighted <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">.
We also solved that one.
Also, when you pass the id to the function it needs to be surrounded by quotes:<a href="#" onclick="hideShow('rowA');">
Link to comment
Share on other sites

justsomeguy tried every other browser, everything works just fine.
I find that hard to believe, but it may be that rowA in that context refers to the element with that ID. If you pass the ID as a string the way you normally would the function will not work in any browser.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...