Solved

Google Chrome - Javascript Problem

Posted on 2008-10-10
20
4,971 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
ID: 22685298
Just to mention the code snippet is used in an IFRAME.
0
 
LVL 5

Expert Comment

by:mverschoof
ID: 22685504
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
ID: 22685525
IMG is the start of a span tag.

for example;

<span id="IMGDaveCestria">
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 5

Expert Comment

by:mverschoof
ID: 22685543
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
ID: 22685554
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
ID: 22685594
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
ID: 22685649
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
ID: 22685949
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
ID: 22685959
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
ID: 22686040
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
 
LVL 6

Author Comment

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

Expert Comment

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

Author Comment

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

Expert Comment

by:mverschoof
ID: 22686205
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
ID: 22686211
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
ID: 22686312
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
ID: 22686336
Not the replace string...
0
 
LVL 5

Expert Comment

by:mverschoof
ID: 22686639
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
ID: 22686698
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
ID: 22686740
where have you placed your element and where is the call to the function?
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
"Eliminate render-blocking JavaScript and CSS in above-the-fold content"  HOW? 6 39
how can i make the array into an object? 4 34
Javascript_Set_dropdown_value 7 34
jqury 17 30
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

823 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