Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Javascript if/else and image display?

Javascript if/else and image display?

Scheduled Pinned Locked Moved Web Development
questionjavascripthelp
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    djhankypark
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • D djhankypark

      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

      M Offline
      M Offline
      Marc Firth
      wrote on last edited by
      #2

      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

      D 2 Replies Last reply
      0
      • M Marc Firth

        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

        D Offline
        D Offline
        djhankypark
        wrote on last edited by
        #3

        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...

        ![](http://pictures.specialcounters.co.uk/covers/<%=(Recordset1.Fields.Item()

        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

        ![](http://pictures.specialcounters.co.uk/<%=(Recordset1.Fields.Item()

        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

        M 1 Reply Last reply
        0
        • M Marc Firth

          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

          D Offline
          D Offline
          djhankypark
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • D djhankypark

            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...

            ![](http://pictures.specialcounters.co.uk/covers/<%=(Recordset1.Fields.Item()

            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

            ![](http://pictures.specialcounters.co.uk/<%=(Recordset1.Fields.Item()

            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

            M Offline
            M Offline
            Marc Firth
            wrote on last edited by
            #5

            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.

            Neonlight

            D 1 Reply Last reply
            0
            • M Marc Firth

              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.

              Neonlight

              D Offline
              D Offline
              djhankypark
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups