Solved

Google Chrome - Javascript Problem

Posted on 2008-10-10
20
4,969 Views
Last Modified: 2008-12-18
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

0
Comment
Question by:davecestria
  • 10
  • 10
20 Comments
 
LVL 6

Author Comment

by:davecestria
Comment Utility
Just to mention the code snippet is used in an IFRAME.
0
 
LVL 5

Expert Comment

by:mverschoof
Comment Utility
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
 
LVL 6

Author Comment

by:davecestria
Comment Utility
IMG is the start of a span tag.

for example;

<span id="IMGDaveCestria">
0
 
LVL 5

Expert Comment

by:mverschoof
Comment Utility
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
 
LVL 6

Author Comment

by:davecestria
Comment Utility
Hello,

Firefox doesn't!

It's for an internal part of the system... so only IE and Chrome support is required.
0
 
LVL 5

Expert Comment

by:mverschoof
Comment Utility
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
 
LVL 6

Author Comment

by:davecestria
Comment Utility
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
 
LVL 5

Expert Comment

by:mverschoof
Comment Utility
I'm sorry, but i don't have any problems here. Everything seems to work.

Don't know what else to tell you
0
 
LVL 6

Author Comment

by:davecestria
Comment Utility
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
 
LVL 5

Accepted Solution

by:
mverschoof earned 500 total points
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 6

Author Comment

by:davecestria
Comment Utility
Strange... tempVehicleReg is deinately there., any suggestions?
0
 
LVL 5

Expert Comment

by:mverschoof
Comment Utility
is the javascript executed before tempVehicleReg is loaded? Sure there are no type-o's?
0
 
LVL 6

Author Comment

by:davecestria
Comment Utility
It all works fine in IE, i think that covers the typo's possibility no?
0
 
LVL 5

Expert Comment

by:mverschoof
Comment Utility
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
 
LVL 6

Author Comment

by:davecestria
Comment Utility
Maybe there is a different way of addressing an element in the parent frame? I'm googling but not finding much.
0
 
LVL 5

Expert Comment

by:mverschoof
Comment Utility
Maybe Chrome doesn't support the replace in the string. Don't know what else it could be
0
 
LVL 6

Author Comment

by:davecestria
Comment Utility
Not the replace string...
0
 
LVL 5

Expert Comment

by:mverschoof
Comment Utility
Then i'm running out of options... i will search around but don't have any more time today.

Probably this weekend
0
 
LVL 6

Author Comment

by:davecestria
Comment Utility
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
 
LVL 5

Expert Comment

by:mverschoof
Comment Utility
where have you placed your element and where is the call to the function?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now