Javascript if/else and image display?
-
Hi There :) I am new to using Javascript and have the need to create a "function" I think, that will display one of 8 images dependant on the content.vlaue of my recordset in asp. I know I need to use an if/else but how do I get the function to hold the img src and onclick link details and then display the relevant picture on my page. If someone could help me I would be very happy. Regards Ray
-
Hi There :) I am new to using Javascript and have the need to create a "function" I think, that will display one of 8 images dependant on the content.vlaue of my recordset in asp. I know I need to use an if/else but how do I get the function to hold the img src and onclick link details and then display the relevant picture on my page. If someone could help me I would be very happy. Regards Ray
Not quite sure what you are trying to do. Please could you explain a little clearer (whats on the page and whats gonna happen when it's clicked). I presume you mean thumbnails, and a main picture which changes when the thumbnails are clicked? you will need something like this In your section: function updateImgSrc(filepath){ var mainImage = document.getElementById('mainImage'); //the big picture mainImage.src = filepath; //set the src of the mainImage to the variable passed in return; } In your section:
And your thumgnails:
Neonlight
-
Not quite sure what you are trying to do. Please could you explain a little clearer (whats on the page and whats gonna happen when it's clicked). I presume you mean thumbnails, and a main picture which changes when the thumbnails are clicked? you will need something like this In your section: function updateImgSrc(filepath){ var mainImage = document.getElementById('mainImage'); //the big picture mainImage.src = filepath; //set the src of the mainImage to the variable passed in return; } In your section:
And your thumgnails:
Neonlight
Hi Neonlight, and thank you for answering I appreciate your time. Basically when my page opens which includes a recordset, one of the fields in the recordset is "genre" i.e. artist, compilation, classical, ost and so on... The code I have on my page at the moment for the image looks like this...

what i need is information/help on how to set out in javascript an if/else statement so that when the page opens it asks, if "genre" = "artist" then the img src = as above ... else if "genre" = "compilation" then img src = as below

else if and so on.. If you could help with information or even point into the right direction it would be much appreciated. Thank you again for your response. Regards Ray
-
Not quite sure what you are trying to do. Please could you explain a little clearer (whats on the page and whats gonna happen when it's clicked). I presume you mean thumbnails, and a main picture which changes when the thumbnails are clicked? you will need something like this In your section: function updateImgSrc(filepath){ var mainImage = document.getElementById('mainImage'); //the big picture mainImage.src = filepath; //set the src of the mainImage to the variable passed in return; } In your section:
And your thumgnails:
Neonlight
Dammit, I think I might have put that code in the wrong type of block or whatever its called cos it seems to have disappeared off the screen...Sorry
-
Hi Neonlight, and thank you for answering I appreciate your time. Basically when my page opens which includes a recordset, one of the fields in the recordset is "genre" i.e. artist, compilation, classical, ost and so on... The code I have on my page at the moment for the image looks like this...

what i need is information/help on how to set out in javascript an if/else statement so that when the page opens it asks, if "genre" = "artist" then the img src = as above ... else if "genre" = "compilation" then img src = as below

else if and so on.. If you could help with information or even point into the right direction it would be much appreciated. Thank you again for your response. Regards Ray
i wouldn't use javascript for this but php or asp. -Store the GET url variables -then a simple if else -use headers (especially "content-type") to allow you to send the correct picture (this makes your asp file send itself as a jpeg or whatever Google these if you are unsure.
-
i wouldn't use javascript for this but php or asp. -Store the GET url variables -then a simple if else -use headers (especially "content-type") to allow you to send the correct picture (this makes your asp file send itself as a jpeg or whatever Google these if you are unsure.
Thanks again Neonlight After a little searching and reading your advice paid off, and not only have I sorted that problem I had but also what would have been my next question :) Thank you for your time much appreciated Regards Ray