?
Solved

Google Chrome - Javascript Problem

Posted on 2008-10-10
20
Medium Priority
?
4,977 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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 2000 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…
Suggested Courses

770 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