Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > function: cannot pass a string and use as an object with netscape!

Reply
Thread Tools

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

 
 
Geniium
Guest
Posts: n/a
 
      11-04-2003
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.
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      11-04-2003


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/

 
Reply With Quote
 
 
 
 
Romain de Wolff
Guest
Posts: n/a
 
      11-04-2003
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!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pass object or use self.object? Tim Arnold Python 10 04-09-2010 07:52 AM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
Cannot create an object of type 'System.String[]' from its representation 'String[] Array' Hessam ASP .Net Building Controls 1 08-16-2003 10:26 AM
Cannot create an object of type 'System.String[]' from its representation 'String[] Array' Hessam ASP .Net Web Controls 0 08-08-2003 08:36 AM
Cannot create an object of type 'System.String[]' from its representation 'String[] Array' Hessam ASP .Net 0 08-08-2003 08:36 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57