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

Discussion in 'Javascript' started by Geniium, Nov 4, 2003.

  1. Geniium

    Geniium Guest

    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.
    Geniium, Nov 4, 2003
    #1
    1. Advertising

  2. 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/
    Martin Honnen, Nov 4, 2003
    #2
    1. Advertising

  3. 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!
    Romain de Wolff, Nov 4, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tom
    Replies:
    0
    Views:
    490
  2. Mickey Segal
    Replies:
    1
    Views:
    657
    Mickey Segal
    May 21, 2004
  3. grbgooglefan
    Replies:
    9
    Views:
    869
    grbgooglefan
    May 9, 2008
  4. Tim Arnold

    pass object or use self.object?

    Tim Arnold, Apr 6, 2010, in forum: Python
    Replies:
    10
    Views:
    399
    Bruno Desthuilliers
    Apr 9, 2010
  5. yaktipper
    Replies:
    10
    Views:
    275
    Richard Cornford
    Jul 10, 2003
Loading...

Share This Page