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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Geniium

    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(obj ect, new_value){
    if (document.all) { // IE
    object.innerHTM L = new_value;
    } else { // Netscape => this DONT work
    object = document.getEle mentById(object );
    object.innerHTM L = new_value;
    }
    }

    2. and an exemple of script calling it :

    change_text(div NameToChange, '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.getEle mentById('divNa meToChange')) 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.
  • Martin Honnen

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



    Geniium wrote:[color=blue]
    > 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(obj ect, new_value){
    > if (document.all) { // IE
    > object.innerHTM L = new_value;
    > } else { // Netscape => this DONT work
    > object = document.getEle mentById(object );
    > object.innerHTM L = new_value;
    > }
    > }
    >
    > 2. and an exemple of script calling it :
    >
    > change_text(div NameToChange, 'new html content);
    >[/color]

    If you have
    <div id="divId"
    then you need to call
    change_text('di vId', '<p>Kibology<\/p>');
    and use
    function change_text(ele mentId, html) {
    if (document.all) {
    document.all[elementId].innerHTML = html;
    }
    else if (document.getEl ementById) {
    document.getEle mentById(elemen tId).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


    Comment

    • Romain de Wolff

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

      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!

      Comment

      Working...