473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

function: cannot pass a string and use as an object with netscape!

Hello,

Im looking to make work my script on both IE and Netscape. It works
fine in IE, but netscape cant handle "dynamic" variables. I need some
help!

Is there a CORRECT way to pass a string as parameter and then use it
as an object in Netscape? IE does that without problem... and Netscape
seems not able to handle it...

1. Here is the function :

function change_text(object, new_value){
if (document.all) { // IE
object.innerHTML = new_value;
} else { // Netscape => this DONT work
object = document.getElementById(object);
object.innerHTML = new_value;
}
}

2. and an exemple of script calling it :

change_text(divNameToChange, 'new html content);

I think u might see my problem... spent few hours looking here and
there, mainly on google... without success. tried many different
things to make the script work.
A workaround is to pass the full object (like
document.getElementById('divNameToChange')) to handle it on netscape,
but I have tonz of line of code using it, I dont want to change
manually all and its not a pretty way to do it.

If you got any idees, shoot! :)

Thanks!

Romain

PS: eval() seems not a good way to do it, and is not working.
Jul 20 '05 #1
2 2041


Geniium wrote:
Im looking to make work my script on both IE and Netscape. It works
fine in IE, but netscape cant handle "dynamic" variables. I need some
help!

Is there a CORRECT way to pass a string as parameter and then use it
as an object in Netscape? IE does that without problem... and Netscape
seems not able to handle it...

1. Here is the function :

function change_text(object, new_value){
if (document.all) { // IE
object.innerHTML = new_value;
} else { // Netscape => this DONT work
object = document.getElementById(object);
object.innerHTML = new_value;
}
}

2. and an exemple of script calling it :

change_text(divNameToChange, 'new html content);


If you have
<div id="divId"
then you need to call
change_text('divId', '<p>Kibology<\/p>');
and use
function change_text(elementId, html) {
if (document.all) {
document.all[elementId].innerHTML = html;
}
else if (document.getElementById) {
document.getElementById(elementId).innerHTML = html;
}
}

That will work without problems with Netscape 6/7, IE4+, Opera 7.
Netscape 4 doesn't allow you to change the innerHTML of an element,
unless it is positioned absolutely where you then need to document.write
the new content.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
Thank you for your answer. The script is working now! :)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Yvan J. Gagnon | last post by:
I am encountering a strange problem in Netscape 7 with a CFM file I am trying to troubleshoot (the page is working fine in NS Communicator and IE). Below is a sample of the problematic line of...
15
by: chirs | last post by:
I am trying to understand a piece of code. In a javascrpit file, there is a function: function ItemStyle(){ var names=; addProps(this,arguments,names,true); }; In the html file, it calls...
7
by: Paul Taylor | last post by:
I want to show a figure based on an numeric entry that more than 20 (or 21and higher). If Number value is 21 or higher then the amount returned is Number value * 120 (£) * 10 (%) to give a...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
4
by: Gerry Abbott | last post by:
Hi All, Im trying to use thie combination but have not had success. Below is the function It tried the following myriskLevel(2,2) myrisklevel(0,0,2) and the ismissing(Three) alwasy...
10
by: Robert Skidmore | last post by:
Take a look at this new JS function I made. It is really simple but very powerful. You can animate any stylesheet numeric value (top left width height have been tested), and works for both % and px...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.