JavaScript prob. - Urgent Help needed

Associate
Joined
22 Jan 2008
Posts
1,074
Location
Stoke-on-Trent
wouldn't usually post a thread like this but my brain hurts :confused:

Having trouble with the below code, the final 'if' - obj doesnt contain what i'm expecting (the object name), according to the alert it just contains [object] :confused:
Code:
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
	<!--alert (obj);-->
	if (obj=='apDiv_contact') {MM_swapImage('Image292','','images/index_17_ovr.jpg',0);}
}
 
without seeing the full code, its a little tricky, but from your description you just need to change that final line to..
Code:
if (obj[b].id[/b]=='apDiv_contact') {MM_swapImage('Image292','','images/index_17_ovr.jpg',0);}
 
without seeing the full code, its a little tricky, but from your description you just need to change that final line to..
Code:
if (obj[b].id[/b]=='apDiv_contact') {MM_swapImage('Image292','','images/index_17_ovr.jpg',0);}

:( nope that just comes back as undefined.
The only other code really relevant to this would be the code used to call the function:
Code:
onMouseUp="MM_showHideLayers('apDiv_contact','','show')"
The show/hide bit of the function works perfectly, it's just that final if statement I need to get working.
 
sorted! well that problem anyway, it still doesn't work tho, because the onMouseOut event overrides the MM_swapImage :( and I don't think there is a way round it.
Here's the code to solve my original problem
Code:
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; <!--alert (args[i]);}-->
	if (args[i]=='apDiv_contact') {MM_swapImage('Image292','','images/index_17_ovr.jpg',0);}
	}
}
The problem was the scope of variables I was trying to check (and the fact that I was trying 'obj' instead of the 'args'. So I moved the } after the obj.visibility to after the final if statement.

For completness (and in the off chance anyone has any ideas) here is the code where the above is called from, which includes the onMouseOut event that is now causing problems :confused:
Code:
		<td rowspan="3">
			<a href="#" 
            onMouseOut="MM_swapImgRestore()" 
            onMouseOver="MM_swapImage('Image292','','images/index_17_ovr.jpg',0)"
            onMouseDown="MM_swapImage('Image292','','images/index_17_dwn.jpg',0)"
            onMouseUp="MM_showHideLayers('apDiv_contact','','show'),MM_swapImage('Image292','','images/index_17_ovr.jpg',0)">
            <img src="images/index_17.jpg" alt="Contact Details" name="Image292" width="16" height="15" border="0"></a></td>
 
I've only quickly glanced at this so I might be way off but:
if "args" is coming back as [object] then try:

if (document.getElementById(args).id=='apDiv_contact')
 
Back
Top Bottom