Results 1 to 8 of 8

Thread: Help with code using Spoiler tag

  1. #1
    Join Date
    Jun 2010
    Posts
    10
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Help with code using Spoiler tag

    I could really use someone's help with what is probably a simple code fix.

    Here's the spoiler code I'm using on a blogger.com page that uses a button to reveal an image and text. Being a one-time only use, I'd like to replace the "Click Here" button with an image (say, of a ticket) that once clicked, reveals the hidden image/text below. Since this is currently working via the button, what in the following code needs to be changed to replace the activation button with an image URL instead (assuming that all code in div class="spoiler" doesn't need to be changed, just the "pre-spoiler code). I like the working code below as it doesn't require any css/javascript.

    Code:
    <div class="pre-spoiler">
    <input 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 = 'Click Here'; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.value = 'Click Here';}" style="font-size: 10px; margin: 0px; padding: 0px; width: 140px;" type="button" value="Click Here" /></div>
    
    <div>
    <div class="spoiler" style="display: none;">
    <a href="IMAGEURL" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" onclick="window.open('IMAGEURL','_blank','toolbar=0, location=0, top=5, left=50, directories=0, status=0, scrollbars=0, resizable=1, copyhistory=0, menuBar=0, width=x, height=y');return(false)"><img alt="" border="0" id="name" src="IMAGEURL_SMALL" width="400" /></a>text</div></div>
    Your help would be really appreciated. Thank you. ~ Raubie
    Last edited by Raubie; 08-12-2010 at 06:12 AM.

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Change the input tag to an img tag using standard HTML: http://www.w3schools.com/tags/tag_img.asp

    You'll probably want to remove this part too;
    Code:
    style="font-size: 10px; margin: 0px; padding: 0px; width: 140px;" type="button" value="Click Here"
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. The Following User Says Thank You to Beverleyh For This Useful Post:

    Raubie (08-12-2010)

  4. #3
    Join Date
    Jun 2010
    Posts
    10
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Smile

    Change the input tag to an img tag using standard HTML: http://www.w3schools.com/tags/tag_img.asp
    Many, many thanks BeverleyH for taking the time to resolve my problem - the "input" tag was giving me grief. I also removed the unnecessary code you highlighted.
    Last edited by Raubie; 08-12-2010 at 05:51 PM.

  5. #4
    Join Date
    Jun 2010
    Posts
    10
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    BeverleyH, I have a followup question if I may.

    How do I replace the image upon onclick with another image of the same dimensions (with the spoiler image/text exposed), and then return the original image on the subsequent click (with the spoiler image/text hidden again)? Can this be done without javascript?

    Thanks again. ~ Raubie
    Last edited by Raubie; 08-12-2010 at 05:52 PM.

  6. #5
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    You'd need javascript I'm afraid - look into jQuery for future projects: http://jquery.com/ and you'll be writing your own functions in minutes.

    Something like this (below) will toggle the button image src and also reveal the spoiler in an attractive slidedown/up motion.

    I'm sure you can see quite easily how the function is built - jQuery references the id's and then tells them to do something based on an effect/event from its internal library (ie - the main jQuery javascript file).

    Code:
    <html>
    <head>
    <title>Spoiler Test</title>
    
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript">
    	$(document).ready(function()
    		{
                   	$('#pre-spoiler').toggle(
                        function()
    			{
                            $('#spoiler').slideDown();
                            $('#button-img').attr('src','images/button-clicked.jpg');
                        	}, 
    			function() 
    			{
                            $('#spoiler').slideUp();
                            $('#button-img').attr('src','images/button.jpg');
                        	});
              	});
    </script>
    
    </head>
    <body>
    
    
    <div id="pre-spoiler">
    	<img src="images/button.jpg" id="button-img"/>
    </div>
    
    <div id="spoiler" style="display:none;">
    	<a href="IMAGEURL" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" onclick="window.open('IMAGEURL','_blank','toolbar=0, location=0, top=5, left=50, directories=0, status=0, scrollbars=0, resizable=1, copyhistory=0, menuBar=0, width=x, height=y');return(false)"><img alt="" border="0" id="name" src="IMAGEURL_SMALL" width="400" /></a>
    	...more content...
    </div>
    
    
    </body>
    </html>
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  7. The Following User Says Thank You to Beverleyh For This Useful Post:

    Raubie (08-13-2010)

  8. #6
    Join Date
    Jun 2010
    Posts
    10
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    This looks great - can't wait to try it out. Thank you again BeverleyH!

  9. #7
    Join Date
    Sep 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi,
    It's very nice script indeed.Is there any options to use three spoilers at once.
    I have tried to but two buttons on my index.page as a result first spoiler has slided down but second one hasn't.I've just copied them and pasted twice without any changes.Would you please to help me with that what have i done wrong?
    Thanks

  10. #8
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    You would simply need to duplicate the script and div arrangement and then substitute in unique IDs;

    Code:
    <html>
    <head>
    <title>Spoiler Test</title>
    
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript">
    	$(document).ready(function()
    		{
                   	$('#pre-spoiler').toggle(
                        function()
    			{
                            $('#spoiler').slideDown();
                            $('#button-img').attr('src','images/button-clicked.jpg');
                        	}, 
    			function() 
    			{
                            $('#spoiler').slideUp();
                            $('#button-img').attr('src','images/button.jpg');
                        	});
    
                   	$('#pre-spoiler2').toggle(
                        function()
    			{
                            $('#spoiler2').slideDown();
                            $('#button-img2').attr('src','images/button2-clicked.jpg');
                        	}, 
    			function() 
    			{
                            $('#spoiler2').slideUp();
                            $('#button-img2').attr('src','images/button2.jpg');
                        	});
              	});
    </script>
    
    </head>
    <body>
    
    
    <div id="pre-spoiler">
    	<img src="images/button.jpg" id="button-img"/>
    </div>
    
    <div id="spoiler" style="display:none;">
    	<a href="IMAGEURL" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" onclick="window.open('IMAGEURL','_blank','toolbar=0, location=0, top=5, left=50, directories=0, status=0, scrollbars=0, resizable=1, copyhistory=0, menuBar=0, width=x, height=y');return(false)"><img alt="" border="0" id="name" src="IMAGEURL_SMALL" width="400" /></a>
    	...more content...
    </div>
    
    
    <div id="pre-spoiler2">
    	<img src="images/button2.jpg" id="button-img2"/>
    </div>
    
    <div id="spoiler2" style="display:none;">
    	<a href="IMAGEURL" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" onclick="window.open('IMAGEURL','_blank','toolbar=0, location=0, top=5, left=50, directories=0, status=0, scrollbars=0, resizable=1, copyhistory=0, menuBar=0, width=x, height=y');return(false)"><img alt="" border="0" id="name" src="IMAGEURL_SMALL" width="400" /></a>
    	...more content...
    </div>
    
    
    </body>
    </html>
    Just follow the same pattern for a 3rd button/div.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

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
  •