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:
else if the database returns the word "image":
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>
else if the database returns the word "image":
<figure class="article-image"><img border="0" alt="" src="detailpage_main_image.jpg"><br>
</figure>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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&
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&
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.
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&
Cd&
You should give a name first to the objects you wnat to show/hide:
if (myVariable=="video) {
myDivName.style.display="i nline";
myFigureName.style.display ="none";
} else {
myDivName.style.display="n one";
myFigureName.style.display ="inline";
}
if (myVariable=="video) {
myDivName.style.display="i
myFigureName.style.display
} else {
myDivName.style.display="n
myFigureName.style.display
}
ASKER
@Sar1973, I am not sure exactly how to code this...
ASKER
The name of the tag is {tag_detailpage_image_or_v ideo} which will return either image or video.
The code for displaying a video is:
The code for displaying a video is:
<div class="shift-to-hero">
<p>{tag_left_video_detailpage_embed}</p>
</div>
The code for displaying an image is:<figure class="article-image">{tag_left_detail_image_01}<br />
</figure>
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.getElem entById("t ag_detailp age_image" )
myFigureName=document.getE lementById ("tag_deta ilpage_vid eo")
or
myDivName=document.getElem entsByName ("tag_deta ilpage_ima ge")
myFigureName=document.getE lementsByN ame("tag_d etailpage_ video")
if I've not misunderstood your last post.
myDivName=document.getElem
myFigureName=document.getE
or
myDivName=document.getElem
myFigureName=document.getE
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
You have not shown us your javascript that is retrieving the values ...