Results 1 to 4 of 4

Thread: [Solved] Spoiler Tag String Help...

  1. #1
    Join Date
    Jan 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default [Solved] Spoiler Tag String Help...

    Hi,

    I don't know if anyone is going to be able to help here or not... Sorry if there's not enough information.

    I'm trying to put a spoiler tag into a .js file so it will display in a forum live preview, but it won't work and FireFox and IE just say there is a syntax error...

    Anyway, here is the code:

    Code:
    ubbcstr=ubbcstr.replace(/\[spoiler\](.*?)\[\/spoiler\]/ig, "<div class='message'><div style='padding-bottom: 1px;'><b>Spoiler:</b> <input type='button' value='Show' onClick='if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = '';		this.innerText = ''; this.value = 'Hide'; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = 'Show'; }'></div><div class='spoiler'><div style='display: none;'>$1</div></div></div>");
    Any help would be appreciated,

    Thanks.
    Last edited by derek barnstorm; 08-11-2008 at 04:04 AM. Reason: Solved

  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

    You can't do this:

    Code:
    onClick='if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = '';		this.innerText = ''; this.value = 'Hide'; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = 'Show'; }'
    Basically what you have is a replacement string. It is delimited by double quotes ("), but contains representations of other string values delimited by single quotes ('). Within these, there are representations of string values delimited by single quotes as well. This wouldn't work if it were an actual string, and will not work here either.

    Generally it is best to delimit your main string with the type of quote most natural to quoted strings within it, and then escape those where they appear within it, using the alternate (other type of) quote within nested strings.

    Assuming that the rest of your code in the replacement string is OK, and that the rest of your code in general is also OK, this would work:

    Code:
    ubbcstr=ubbcstr.replace(/\[spoiler\](.*?)\[\/spoiler\]/ig, "<div class=\"message\"><div style=\"padding-bottom: 1px;\"><b>Spoiler:</b> <input type=\"button\" value=\"Show\" onclick=\"if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = '';	this.innerText = ''; this.value = 'Hide'; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = 'Show'; }\"></div><div class=\"spoiler\"><div style=\"display: none;\">$1</div></div></div>");
    There could be other problems.
    - John
    ________________________

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

  3. #3
    Join Date
    Jul 2008
    Posts
    102
    Thanks
    36
    Thanked 6 Times in 6 Posts

    Default

    well thats because your trying to get IE to work... theres your first problem.

    Ive read up that IE8 is going to be 100% W3C compliant, Im not sure if its another MS lie but they have another EU case on their backs. IE8 should be complete before the year is up.

    You can download the developer toolkit for IE7 to see how messed up your code gets. Expect your heart to sink when you see the tragerty of how bad IE messes with "YOUR" code.

    I've give up on trying to work around it but there seems to be light at the end of the tunnel, just hope its not a train!

    Kind regards
    Dal
    Programmers are tools used to convert Caffeine to code

  4. #4
    Join Date
    Jan 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you so much for that jscheuer1... It works perfectly, I wasn't expecting a solution like that... It was my fault for trying to get away with single quote rather than back slashing them then...

    Thanks again!

    Yeah Dal, I try to stay way from IE... I always dread testing my work on it...

    Cheers!

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
  •