Results 1 to 4 of 4

Thread: Help regarding innerHTML

  1. #1
    Join Date
    Dec 2005
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow Help regarding innerHTML

    Hi,
    I used innerHTML like the following.
    <script>
    td_id.innerHTML="<script>functionname(param);</script>";
    </script>

    But this is not working. Can anyone help to solve this.

    Regards,
    Karthik.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Assuming that:

    td_id

    is a valid object that supports an innerHTML object (if it is, it would have needed to have been defined as such elsewhere and before this code is executed), the slash (/) should be escaped (\/) to contribute to the page's potential to pass validation. More importantly, you need to break up the </script> tag in the string literal. Otherwise, the script parser thinks it is the end of the script:

    Code:
    td_id.innerHTML="<script>functionname(param);<"+"\/"+"script>";
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Dec 2005
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanx John, it's working fine

  4. #4
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1
    td_id.innerHTML="<script>functionname(param);<"+"\/"+"script>";[/]
    That's rather excessive:

    Code:
    td_id.innerHTML = '<script type="text/javascript">functionname(param);<\/script>';
    Notice that all that is necessary is a simple slash.

    Mike

Bookmarks

Posting Permissions

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