Click to See Complete Forum and Search --> : is null or not an object error !! Help


Jtcarlson3
09-18-2004, 02:47 PM
Hello,

I am getting a 'objIframe' is null or not an object error on this page http://www.findgolfusa.com/arizona_index.asp?Ad=8 , its a java error in the menu status bar on the bottom. Sometimes it doesnt show up on load and sometimes it does. Also some ppl dont get this error at all and the map links on that map work for some and others it doesnt work and gives that error when you click on one of the map links. Basically the javascript is a .hash switch case that is telling it what file to load in the iframe depending on what link you click. I have tried everything and can not figure out why its doing this. It runs perfect if I run it locally but I get the errors and it doesnt work if I run it from the web. Alot of my friends run it from the web and it works sometimes for them and sometimes not.. Any ideads ??

Code for the script;

<script language="javascript" defer>
var strHash = location.hash;
var objIframe = document.getElementById('main');
var objAframe = document.getElementById('ads');
//-->var stCounty = <% Response.Write(strCounty) %>;
//-->var stAd = <% Response.Write(intAd) %>;
switch (strHash)
{
case "#arizona":
objIframe.src = 'maps/arizona2.htm';
break;
case "#apache":
objIframe.src = 'maps/az_apache_map.htm';
break;
case "#cochise":
objIframe.src = 'maps/az_cochise_map.htm';
break;
case "#coconino":
objIframe.src = 'maps/az_coconino_map.htm?Ad=5';
break;
case "#gila":
objIframe.src = 'maps/az_gila_map.htm?Ad=4';
break;
case "#graham":
objIframe.src = 'maps/az_graham_map.htm';
break;
case "#greenlee":
objIframe.src = 'maps/az_greenlee_map.htm';
break;
case "#la_paz":
objIframe.src = 'maps/az_la_paz_map.htm?Ad=5';
break;
case "#maricopa":
objIframe.src = 'maps/az_maricopa_map.htm?Ad=6';
break;
case "#mohave":
objIframe.src = 'maps/az_mohave_map.htm?Ad=8';
break;
case "#navajo":
objIframe.src = 'maps/az_navajo_map.htm?Ad=10';
break;
case "#pima":
objIframe.src = 'maps/az_pima_map.htm';
break;
case "#pinal":
objIframe.src = 'maps/az_pinal_map.htm';
break;
case "#santa_cruz":
objIframe.src = 'maps/az_santa_cruz_map.htm';
break;
case "#yavapai":
objIframe.src = 'maps/az_yavapai_map.htm?Ad=5';
break;
case "#yuma":
objIframe.src = 'maps/az_yuma_map.htm';
break;
default:
objIframe.src = 'maps/arizona2.htm';
}



And on the map page with the links I just add in #gila (example) on the link..

Thanks
Joe

Jtcarlson3
09-18-2004, 08:38 PM
So I got this to work finally changing it to a function instead of using defer method. But now this page will only work on PC MSIE. It has stopped working all together now on Mac either IE or Safari. What part of the script doesnt run on MAC ?

New Code that works on PC;

function loadMainIframe(){
var strHash = location.hash;
var objIframe = document.getElementById('main');
if(strHash && strHash != "")
{
var objAframe = document.getElementById('ads');
//-->var stCounty = <% Response.Write(strCounty) %>;
//-->var stAd = <% Response.Write(intAd) %>;
switch (strHash)
{
case "#arizona":
objIframe.src = 'maps/arizona2.htm';
break;
case "#apache":
objIframe.src = 'maps/az_apache_map.htm';
break;
case "#cochise":
objIframe.src = 'maps/az_cochise_map.htm';
break;
case "#coconino":
objIframe.src = 'maps/az_coconino_map.htm?Ad=5';
break;
case "#gila":
objIframe.src = 'maps/az_gila_map.htm?Ad=4';
break;
case "#graham":
objIframe.src = 'maps/az_graham_map.htm';
break;
case "#greenlee":
objIframe.src = 'maps/az_greenlee_map.htm';
break;
case "#la_paz":
objIframe.src = 'maps/az_la_paz_map.htm?Ad=5';
break;
case "#maricopa":
objIframe.src = 'maps/az_maricopa_map.htm?Ad=6';
break;
case "#mohave":
objIframe.src = 'maps/az_mohave_map.htm?Ad=8';
break;
case "#navajo":
objIframe.src = 'maps/az_navajo_map.htm?Ad=10';
break;
case "#pima":
objIframe.src = 'maps/az_pima_map.htm';
break;
case "#pinal":
objIframe.src = 'maps/az_pinal_map.htm';
break;
case "#santa_cruz":
objIframe.src = 'maps/az_santa_cruz_map.htm';
break;
case "#yavapai":
objIframe.src = 'maps/az_yavapai_map.htm?Ad=5';
break;
case "#yuma":
objIframe.src = 'maps/az_yuma_map.htm';
break;
default:
objIframe.src = 'maps/arizona2.htm';
}
}
else
objIframe.src = 'maps/arizona2.htm';
}



And Added onLoad="loadMainIframe()" to the Body Tag.

Joe

Jtcarlson3
09-19-2004, 12:25 AM
I went ahead and just tried a few other things and finally got another solution using only .asp. Seems alot faster now also. Plus works on PC IE , MAC safari and IE.

Deleted the body onload tag and killed that function completely and just put this in where the iframe code use to be.

<%
Dim selectedCounty
Dim CountyURL
CountyURL = Request.QueryString("County")

Select case CountyURL

case "apache"
selectedCounty = "maps/az_apache_map.htm"
case "yuma"
selectedCounty = "maps/az_yuma_map.htm"
case "cochise"
selectedCounty = "maps/az_cochise_map.htm"
case "coconino"
selectedCounty = "maps/az_coconino_map.htm"
case "gila"
selectedCounty = "maps/az_gila_map.htm"
case "graham"
selectedCounty = "maps/az_graham_map.htm"
case "greenlee"
selectedCounty = "maps/az_greenlee_map.htm"
case "la_paz"
selectedCounty = "maps/az_la_paz_map.htm"
case "maricopa"
selectedCounty = "maps/az_maricopa_map.htm"
case "mohave"
selectedCounty = "maps/az_mohave_map.htm"
case "navajo"
selectedCounty = "maps/az_navajo_map.htm"
case "pima"
selectedCounty = "maps/az_pima_map.htm"
case "pinal"
selectedCounty = "maps/az_pinal_map.htm"
case "santa_cruz"
selectedCounty = "maps/az_santa_cruz_map.htm"
case "yavapai"
selectedCounty = "maps/az_yavapai_map.htm"
case else
selectedCounty = "maps/arizona2.htm"
end select

response.write "<iframe width='627' src='" & selectedCounty & "' name='main' height='652' align='left' frameborder='0' scrolling='no'></iframe>" %>

Works good now. Just posting this case anyone else ever needs this as a ref.