Solved

how to display or hide an image based upon javascript variable

Posted on 2009-05-14
2
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
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:
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

630 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