Jump to content
  • 0

Conditional Image Display


Gwen

Question

I want to display an image file only if a specific condition occurs. How can I display the image from within a Javascript?

The conditional test is working - I can do a document.write ("Accredited Test Center") but I can't get an image to display. Any suggestions????

var v_url = "[@field:Accredited_Certified]" ;

if (v_url = "Accredited Test Center") {

document.write ("Posted Image };

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Now I need to change the conditional from = to "contains". How can I do this?

If v_url contains the string "abcd" then I want to display the image.

Here's the current code:

var v_url = "[@field:Accredited_Certified]" ;

if (v_url == "Accredited Test Center") {

document.write ("Posted Image};

Thanks!

Link to comment
Share on other sites

  • 0

To search for a specific value in a string you can use indexOf method in Java Script such as:

string.indexOf(searchstring)

This method returns the position of the first occurrence of a specified value in a string. If the specified value is not found the method returns -1. Please learn more information about this at http://www.w3schools.com/jsref/jsref_indexof.asp.

For example in your case you can have:

if (v_url.indexOf("Accredited Test Center") != -1){

...

..

}

Link to comment
Share on other sites

  • 0

I was able to get the result "-1" to display. So it's not finding a string match. I tried to display the string but it doesn't print. Is is possible that because this is using a View rather than a table that the @field needs to be different to access the field?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...