Solved

how to display or hide an image based upon javascript variable

Posted on 2009-05-14
2
256 Views
Last Modified: 2013-12-07
Trying to properly test GWO.. all pages and data are dynamic with URL rewites.  I want to be able to display or hide images for google website optimizer testing

My idea is to have this javascipt
<script type="TEXT/JAVASCRIPT">var display=1
</script>
which i can then not be used in a GWO option

then later when the images are displayed they are hidden if display is not 1

the image is shown by a function call
tep_image(DIR_WS_IMAGES . $categories['categories_image'], $categories['categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT,parameters)

parameters can be style="display: none;" which hides the image... I know how to do this with an onclick or other event but do not know how to show or hide the image (or text block or whatever) based on whether a javascript variable is set earlier

Though this question is specific it is general in that I am looking for a way to display or hide  a php produced html block with javascript so I can perform GWO tests
0
Comment
Question by:levelninesports
2 Comments
 
LVL 7

Accepted Solution

by:
tg_wilk earned 500 total points
ID: 24391311
If you set all images to display: none at the beginning, you can iterate through all images at the bottom of the page and set display to inline or block, if display variable is set:
<script type="text/javascript">
if (display == 1)
{
    var images = document.getElementsByTagName("img");
    for(var j=0; j<images.length; j++)
    {
       if (images[j].style.display == 'none') images[j].style.display='inline';
    }
}
</script>

Open in new window

0
 

Author Closing Comment

by:levelninesports
ID: 31581747
thanks worked great.. just for completeness the image display line read
tep_image(DIR_WS_IMAGES . $categories['categories_image'], $categories['categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT,'id="img" style="display: none;"')
the end part being the relevant piece
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This video teaches users how to migrate an existing Wordpress website to a new domain.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question