Link to home
Start Free TrialLog in
Avatar of swaggrK
swaggrK

asked on

Javascript If/Else Statement

I need to write some javascript that shows different lines of code based on whether "image" or "video" was returned from my database.

If the return from the database is the word "video" the following will display:

<div class="shift-to-hero">
<p>{tag_left_video_detailpage_embed}</p>
</div>

Open in new window


else if the database returns the word "image":
<figure class="article-image"><img border="0" alt="" src="detailpage_main_image.jpg"><br>
</figure>

Open in new window

Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

How is Video / Image beeing returned?

You have not shown us your javascript that is retrieving the values ...
ASKER CERTIFIED SOLUTION
Avatar of oheil
oheil
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Where is you code for what is returned from the database?  not sure it would be javascript but rather asp.net
Why would you use javascript instead of just generating the code on the server before the page is returned.  Unless you are doing this with some kind of ajax operation it makes zero sense to do it with javascript.

even if it is javascipt then you still write a container tag in the page during generation, and then just put your code into the innerHTML of the container.

Cd&
Avatar of swaggrK
swaggrK

ASKER

I am using Adobe Business Catalyst and I all I have are the values of what it is returned.
The value will either be "video" or "image"

From what I have read, the system does not really employ conditional statements and so what I am trying to do is a bit of hack.
Post a link to the page please.  If you are using third party code that handcuffs you and forces a hack, we will need to see what is possible.

Cd&
You should give a name first to the objects you wnat to show/hide:
if (myVariable=="video) {
      myDivName.style.display="inline";
      myFigureName.style.display="none";
} else {
      myDivName.style.display="none";
      myFigureName.style.display="inline";
}
Avatar of swaggrK

ASKER

@Sar1973, I am not sure exactly how to code this...
Avatar of swaggrK

ASKER

The name of the tag is {tag_detailpage_image_or_video} which will return either image or video.


The code for displaying a video is:
<div class="shift-to-hero">
<p>{tag_left_video_detailpage_embed}</p>
</div>

Open in new window

The code for displaying an image is:
<figure class="article-image">{tag_left_detail_image_01}<br />
</figure>

Open in new window

What are you using to get the values from the database? Can you show all your code please. Ite the Adobe catalyst code
So take a chance with the code above adding before the if/else statement:
myDivName=document.getElementById("tag_detailpage_image")
myFigureName=document.getElementById("tag_detailpage_video")
or
myDivName=document.getElementsByName("tag_detailpage_image")
myFigureName=document.getElementsByName("tag_detailpage_video")
if I've not misunderstood your last post.
Either way we need to see more code to be sure. Please post your server side code and the html for the entire page if possible