Solved

how to display or hide an image based upon javascript variable

Posted on 2009-05-14
2
258 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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
Passing client data from form to server 5 56
Problem in javascript 17 58
Expanding/Collapsing Tree on SharePoint List 29 63
How do I buy BitCoin? 4 27
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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 is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

734 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