Google Chrome - Javascript Problem

Hello Experts,

Having a little trouble with Google Chrome and some bit of my JavaScript. The snippet below woks fine in IE 7 but not in Chrome. Could someone please advise why it wouldn't? And a solution to the problem.

All it does is hide a green tick when the user selects a different name, very simple stuff... supposedly.

Thanks in advance.
function switchName(strName,strEmp){
		var oldName = parent.document.getElementById('tempName').value.replace(' ','');
		document.getElementById('IMG'+oldName).innerHTML = '';
		document.getElementById('IMG'+strName.replace(' ','')).innerHTML = '<img src="../../content/images/green_tick.gif" width="16" height="16">';
		
		if(strName == 'CUSTOM'){
			parent.document.getElementById('tempName').value = document.getElementById('customName').value;
			parent.document.getElementById('tempEmployer').value = document.getElementById('customEmployer').value;
		}else{
			parent.document.getElementById('tempName').value = strName;
			parent.document.getElementById('tempEmployer').value = strEmp;
		}
	}

Open in new window

LVL 6
davecestriaAsked:
Who is Participating?
 
mverschoofConnect With a Mentor Commented:
Might have just been in IE. Now the error appears in FireFox.

parent.document.getElementById("tempVehicleReg") is null

That is your problem. It is possible the element isn't found, or that the element isn't declared before you call to it
0
 
davecestriaAuthor Commented:
Just to mention the code snippet is used in an IFRAME.
0
 
mverschoofCommented:
Doesn't the following code insert the <img src...> into another <img> tag?

Do you have a test file or something to show the problem?
document.getElementById('IMG'+strName.replace(' ','')).innerHTML = '<img src="../../content/images/green_tick.gif" width="16" height="16">';

Open in new window

0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
davecestriaAuthor Commented:
IMG is the start of a span tag.

for example;

<span id="IMGDaveCestria">
0
 
mverschoofCommented:
Oh, that makes a lot of sense. Still trying to figure out why CHrome won't support it.

Do Firefox, Opera and Safari work properly?
0
 
davecestriaAuthor Commented:
Hello,

Firefox doesn't!

It's for an internal part of the system... so only IE and Chrome support is required.
0
 
mverschoofCommented:
Ok but Chrome is a lot like FireFox so if it worked in FF it would be a lot more difficult.

If there is a file i could use to test that would be great. I have some developer tools to check your javascript so if you have something online it would make things a lot easier and quicker
0
 
davecestriaAuthor Commented:
I would prefer not to post the address on a public site... could you please send me an email and i will reply with the address;

dave at cestriadistribution.com

Cheers :o)
0
 
mverschoofCommented:
I'm sorry, but i don't have any problems here. Everything seems to work.

Don't know what else to tell you
0
 
davecestriaAuthor Commented:
So when you cick on a vehicle, a modal message opens up, then when you click on a different entry in the list, the green tick appaers next to the clicked entry?
0
 
davecestriaAuthor Commented:
Strange... tempVehicleReg is deinately there., any suggestions?
0
 
mverschoofCommented:
is the javascript executed before tempVehicleReg is loaded? Sure there are no type-o's?
0
 
davecestriaAuthor Commented:
It all works fine in IE, i think that covers the typo's possibility no?
0
 
mverschoofCommented:
That's true. But this type of problem usually occurs when javascript calls a non-existing or non declared element. So the element may not exist when you run the script. This often works differently in IE and non-IE explaining the difference
0
 
davecestriaAuthor Commented:
Maybe there is a different way of addressing an element in the parent frame? I'm googling but not finding much.
0
 
mverschoofCommented:
Maybe Chrome doesn't support the replace in the string. Don't know what else it could be
0
 
davecestriaAuthor Commented:
Not the replace string...
0
 
mverschoofCommented:
Then i'm running out of options... i will search around but don't have any more time today.

Probably this weekend
0
 
davecestriaAuthor Commented:
Hmmm, something as simple as this is causing the same error without even using IFRAMES;
function gV(idToRetrieve){
      return document.getElementById(idToRetrieve).value;
}
alert(gV('Mate5355'));

I HATE GOOGLE & FIREFOX

0
 
mverschoofCommented:
where have you placed your element and where is the call to the function?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.