Gwen Posted August 5, 2009 Report Share Posted August 5, 2009 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 (" }; Quote Link to comment Share on other sites More sharing options...
0 bahar_vm Posted August 7, 2009 Report Share Posted August 7, 2009 img tag is not correct in your code, see below for the correct one. var v_url = "[@field:Accredited_Certified]" ; if (v_url == "Accredited Test Center") { document.write ("}; Best, Bahar M. Quote Link to comment Share on other sites More sharing options...
0 Gwen Posted August 7, 2009 Author Report Share Posted August 7, 2009 Thanks for the suggestion. Unfortunately it still doesn't work. Are you sure an Gwen Quote Link to comment Share on other sites More sharing options...
0 Gwen Posted August 7, 2009 Author Report Share Posted August 7, 2009 I got it to work! The end paren was missing. Thanks! Quote Link to comment Share on other sites More sharing options...
0 Gwen Posted June 26, 2011 Author Report Share Posted June 26, 2011 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 ("}; Thanks! Quote Link to comment Share on other sites More sharing options...
0 bahar_vm Posted June 26, 2011 Report Share Posted June 26, 2011 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){ ... .. } Quote Link to comment Share on other sites More sharing options...
0 Gwen Posted June 29, 2011 Author Report Share Posted June 29, 2011 Thanks. I cannot figure out what I'm doing wrong. I tested the document.write ("") }; if (v_cert.indexOf("GS1 US Certified Barcode Products")!= -1){ document.write ("") }; Quote Link to comment Share on other sites More sharing options...
0 Gwen Posted June 29, 2011 Author Report Share Posted June 29, 2011 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? Quote Link to comment Share on other sites More sharing options...
Question
Gwen
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 (" };
Link to comment
Share on other sites
7 answers to this question
Recommended Posts
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.