Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

document.getElementById()-has no properties error

Status
Not open for further replies.

rayesteq

Programmer
Oct 27, 2004
5
TR
Hi everyOne;

I wrote this JS for my webPage but;I couldnt make it work for Mozilla or Firefox and I couldn't find a proper solution.Can you help me about this?
I want to change my buttons images without refreshing the frame.But in Mozilla and Firefox document.getElementById() returns me "has no properties " error.What can i do for solving this problem and work my JS for them...


Thanks for Your consideration

Best Regards


<script language="JavaScript">

root="";
rootImg="";

var prevClicked = "";
var prevImagename ="";

Fullpath="Imgpath="../images/styleguide/";


function setRoot(rootId,rootImage)
{
root=rootId;
rootImg=rootImage;
}



function SwapImageMouseOver(current,imgName)
{
tmpStr2 = current.toString();
var source="";


if(document.getElementById){
source = document.getElementById(current).src.toString();
}else if(document.all)
{
source = document.all[current].src.toString();
}else if(document.layers)
{
source = document.layers[current].src.toString();
}

var controlsource=Fullpath+imgName+'_prs.gif';


if(source.toString() != controlsource.toString())
{
if(document.getElementById){
document.getElementById (current).src=Imgpath+imgName+'_ovr.gif';
}else if (document.all){
document.all[current].src=Imgpath+imgName+'_ovr.gif';
}else if(document.layers){
document.layers[current].src=Imgpath+imgName+'_ovr.gif';
}
}



}


function SwapImageMouseOut(current,imgName) {

tmpStr2 = current.toString();
var source = "";
var controlsource=Fullpath+imgName+'_prs.gif';

if(document.getElementById){
source = document.getElementById(current).src.toString();
}else if(document.all)
{
source = document.all[current].src.toString();
}else if(document.layers)
{
source = document.layers[current].src.toString();
}




if(source.toString() !=controlsource.toString())
{
if(document.getElementById){
document.getElementById (current).src=Imgpath+imgName+'_def.gif';
}else if (document.all){
document.all[current].src=Imgpath+imgName+'_def.gif';
}else if(document.layers){
document.layers[current].src=Imgpath+imgName+'_def.gif';
}

}

}



</script>
 

Without knowing the exact parameters you are passing in to the SwapImageMouseOver function, it would be hard to say exactly.

However, given that you are calling the "toString" method of "current" as the first line, I can only assume that "current" is not a string variable - otherwise why would you be executing the method?

With that in mind, and knowing that the getElementById method takes a string as a parameter, could this be the root of your problem?

If you can post the HTML code that calls the JS code, it might be easier to confirm or exclude this.

Hope this helps,
Dan
 
This is my Html and I am still searching my problem;unfortunetly I haven't found the solution yet.

Thans For Your consideration

Best Regards

Code:
<html>
  
<!-- Mirrored from ssp.ma-design.de by HTTrack Website Copier/3.x [XR&CO'2001] -->

<head>

<script language="JavaScript">
 
root="";
rootImg="";

var prevClicked = "";
var prevImagename ="";

Fullpath="[URL unfurl="true"]http://sdt.testserver.macio.de/images/styleguide/";[/URL]
Imgpath="../images/styleguide/";


function setRoot(rootId,rootImage)
{
root=rootId;
rootImg=rootImage;
}


function staySet(curr,imgName){


tmpStr1= curr.toString();
if (prevClicked == "")
{     
  
    if(document.getElementById){
    document.getElementById(root).src=Imgpath+rootImg+'_def.gif';
    document.getElementById(curr).src=Imgpath+imgName+'_prs.gif'; 
    
    }else if (document.all){
    document.all[root].src=Imgpath+rootImg+'_def.gif';
    document.all[curr].src=Imgpath+imgName+'_def.gif';
    
    }else if (document.layer){
    document.layers[root].src=Imgpath+rootImg+'_def.gif';
    document.layers[curr].src=Imgpath+imgName+'_def.gif'
 
    }
   
    prevClicked = curr;
    prevImageName=imgName;

    root=curr;
    rootImg=imgName;
}
else
{
    if(document.getElementById){
     document.getElementById (prevClicked).src=Imgpath+prevImageName+'_def.gif'; 
     document.getElementById(curr).src=Imgpath+imgName+'_prs.gif'; 
     }
     else if (document.all){
    
     document.all[prevClicked].src=Imgpath+prevImageName+'_def.gif'; 
     document.all[curr].src=Imgpath+imgName+'_prs.gif'; 

     }else if(document.layers)
    {
    document.layers[prevClicked].src=Imgpath+prevImageName+'_def.gif'; 
     document.layers[curr].src=Imgpath+imgName+'_prs.gif';
    }   
    prevClicked = curr;
    prevImageName=imgName;

    root=curr;
    rootImg=imgName;

  }

}


function SwapImageMouseOver(current,imgName) 
{
   tmpStr2 = current.toString();
   var source="";
  

 if(document.getElementById){  
  source = document.getElementById(current).src.toString();
 
  }else if(document.all)
  {
  source = document.all[current].src.toString();
  }else if(document.layers)
  {
  source = document.layers[current].src.toString();
  }

  var controlsource=Fullpath+imgName+'_prs.gif';


if(source.toString() != controlsource.toString())
  {
  if(document.getElementById){
  document.getElementById(current).src=Imgpath+imgName+'_ovr.gif';
  }else if (document.all){
  document.all[current].src=Imgpath+imgName+'_ovr.gif';
  }else if(document.layers){
  document.layers[current].src=Imgpath+imgName+'_ovr.gif';
  }
   }



}


function SwapImageMouseOut(current,imgName) {

tmpStr2 = current.toString();
var  source = "";
var controlsource=Fullpath+imgName+'_prs.gif';

if(document.getElementById){  
  source = document.getElementById(current).src.toString();
   
  }else if(document.all)
  {
  source = document.all[current].src.toString();
  }else if(document.layers)
  {
  source = document.layers[current].src.toString();
  }




if(source.toString() !=controlsource.toString())
{
if(document.getElementById){
  document.getElementById(current).src=Imgpath+imgName+'_def.gif';
  }else if (document.all){
  document.all[current].src=Imgpath+imgName+'_def.gif';
  }else if(document.layers){
  document.layers[current].src=Imgpath+imgName+'_def.gif';
  }

}

}


 
</script>

    
  <title>Saurer Software Solution Portal</title>
  

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <meta name="generator" content="REDWork">
     

</head>
   
	  <body bgcolor="#ffffff" style="margin:0px; padding:0px; 

background-image:url(../images/styleguide/555x89_barmag_imagery_def.gif); background-attachment:fixed; 

background-repeat:no-repeat;">

 
 
 
  
 
       
 <table border="0" cellspacing="0" cellpadding="0" width="100%" style="margin:0px; padding:0px; 

background-image:url(../images/blackblue.gif); background-repeat:repeat-x; background-position:0px 0px;">
      <tr valign="top">
        <td width="0">
          <img src="../images/1x1.gif" width="0" height="20" border="0" /><br />
        </td>
          <!-- Navigation Terminal begin -->
        <td>

          <img src="../images/1x1.gif" width="10" height="10" border="0" /><br />
          <table border="0" cellspacing="0" cellpadding="0" width="1">
            <tr valign="bottom">
              <td>
							<td><img src="../images/styleguide/appl_sdt_def.gif"></td><td> <td>

<a 
  
  onmouseover="SwapImageMouseOver(898839274,'main_home')"
  onmouseout="SwapImageMouseOut(898839274, 'main_home')"
   

      onclick="javascript:staySet(898839274,'main_home');parent.frames[7].location.href='/redwork/do.php?layoutid=350&nodeid=836278614&language=1&usersession=<';parent.frames[1].location.href='/redwork/do.php?layoutid=6001&node=836278614&language=1&usersession=<';parent.frames[6].location.href='/redwork/do.php?layoutid=6004&nodeid=898839274&language=1&usersession=<';"
      href="/redwork/do.php?layoutid=6002&nodeid=898839274&usersession=<"
      target="navigation">  
<img name="898839274"  src="../images/styleguide/main_home_prs.gif" border="0" /></a>

<script language="JavaScript">setRoot(898839274,'main_home');</script></td><td> <td>

<a 
  
  onmouseover="SwapImageMouseOver(2146912657,'main_d-track')"
  onmouseout="SwapImageMouseOut(2146912657, 'main_d-track')"
   

      onclick="javascript:staySet(2146912657,'main_d-track');parent.frames[7].location.href='/redwork/do.php?layoutid=350&nodeid=2146912655&language=1&usersession=<';parent.frames[1].location.href='/redwork/do.php?layoutid=6001&node=2146912655&language=1&usersession=<';parent.frames[6].location.href='/redwork/do.php?layoutid=6004&nodeid=2146912657&language=1&usersession=<';"
      href="/redwork/do.php?layoutid=6002&nodeid=2146912657&usersession=<"
      target="navigation">  
<img name="2146912657"  src="../images/styleguide/main_d-track_def.gif" border="0" /></a>

</td>							</td>
	
           <td width="620" background="../images/styleguide/sub_empty.gif"></td>
          <td align="right" nowrap="nowrap">
          <!-- Logo begin -->
          <img src="../images/1x1.gif" width="266" height="72" valign="bottom" border="0">
          


<img src="../images/styleguide/logo.gif" border="0" align="rigth" hspace="300" /><br />
          <!-- Logo end -->

        </td> 
							
							
</table>
        

</html>[code]
 

Erm... Where have you defiend any of the elements you are wishing to affect? There is no element with the id "898839274", for example... And while there is an image with the NAME of "2146912657", a NAME in no way constitutes an ID. Stick to one method of accessing your images - getElementById (as the name implies) gets objects by ID, not by NAME.

Hope this helps,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top