Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation PROTOTYPE Strange element.update() behavior

    Hi everyone. I need to specify the innerHTML of an element but I've been having strange problems using innerHTML as well as Prototype's .update() function. Let's say I have this code:

    alert(defaultcontent); //show the string of defaultcontent variable.
    someelement.update(defaultcontent); //applies it to the element
    alert(someelement.innerHTML); //shows the resulting content of the element

    I've tried with several defaultcontent strings. With all of them the msg boxes show the same string as expected. This does well with both methods innerHTML and Prototype's update function. And it works in both IE and FF.

    But I have a special string that brings me problems:

    defaultcontent = '<TR><TH>City</TH><TH>State</TH></TR>';

    I always get the first alert box with the string. But the second time it comes changed. Meaning that something happened when applying the HTML string to the element. The results I'm getting are:

    in FF using innerHTML:
    'CityState'

    in FF using Prototype's update:
    'CityState'

    in IE using innerHTML:
    'City</TH><TH>State</TH></TR>'
    +Unknown runtime error.

    in IE using Prototype's update:
    Error. Object does not support this property or method.

    IE with innerHTML is getting closer to the expected result, but the runtime error is something unbearable. But it sounds strange to me that in FF, both methods remove all HTML tags.

    What could be wrong??

  • #2
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Up to now, I have found a solution that works in FF and IE. The solution is using the BetterInnerHTML function by Craig Buckler from Optimal Works.

    The thing is working fine. But I don't see why I have to add more libraries if I'm using already Prototype Framework. Well, congratulations for Craig Buckler.

  • #3
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts
    ths solutions might also be not to use a framework, what you are trying to do is extremely simple.with plain javascript you would have your piece of code hence "you would know what you have" with prototype or other library you have an abstraction layer of one hundreds or more lines to start your search for debugging a two line code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •