Changing the src and onmousedown URL with user input

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Joe Strom
    New Member
    • Jul 2011
    • 5

    Changing the src and onmousedown URL with user input

    Im trying to make a script to change 3 links with user input, so when a user trys to change LINK1, it will go to all the LINK1 spots, same with LINK2 and LINK3.

    Code:
    <table style="background-color: black;" border="0"
    cellpadding="6" cellspacing="0">
    <tbody>
    <tr>
    <td colspan="3" valign="top" width="300"
    height="230">
    <center><font color="white" face="trebuchet ms"
    size="3"><b><i>Imageviewer<br>
    </i></b></font><img
    src="LINK1"
    name="prodimg" id="prodimg" width="285"><br>
    <br>
    </center>
    </td>
    </tr>
    <tr>
    <td>
    <center><img
    src="LINK1"
    onmousedown="document.images['prodimg'].src='LINK1';"
    width="70"> </center>
    </td>
    <td>
    <center><img
    src="LINK2"
    onmousedown="document.images['prodimg'].src='LINK2';"
    width="70"> </center>
    </td>
    <td>
    <center><img
    src="LINK3"
    onmousedown="document.images['prodimg'].src='LINK3';"
    width="70"> </center>
    </td>
    <!--PICS--> </tr>
    </tbody>
    </table>

    Any help would be appreciated
    Last edited by Dormilich; Jul 20 '11, 09:47 PM. Reason: please use [CODE] [/CODE] tags when posting code
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    I have no idea what you're trying to do. First of all, you're saying you're changing links. But you're actually changing the source for an image. So I don't know if you actually want to change links or you want to change images.

    Second, the code seems to work as intended. Which means you're trying to do something not intended. Which you have not explained clearly.

    Comment

    • Joe Strom
      New Member
      • Jul 2011
      • 5

      #3
      The code works as its supposed to now, but i want to be able to have another person(sales staff) to be able to input three links to the different pictures, in order to change the links themselves without dealing with the code part.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        In the on load event of the body, store the 3 "links" in global variables. And in your code, use those variables instead. Then the user just needs to change the image source in the html without having to change the code.

        Comment

        • Joe Strom
          New Member
          • Jul 2011
          • 5

          #5
          Seems like its a little above my level. How would the code look with that?

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            I make no guarantees for the code, I did not test it. But it gets the point across.
            Code:
            <html>
            	<head>
            		<script type="text/javascript">
            			var link1, link2, link3
            			
            			function loadLinks() {
            				link1 = document.getElementById("link1");
            				link2 = document.getElementById("link2");
            				link3 = document.getElementById("link3");
            			}
            		</script>
            	</head>
            	
            	<body onload="loadLinks();">
            		<img id="masterimg" src="image1.jpg" />
            	
            		<img id="link1" src="image1.jpg" onclick="document.getElementById('masterimg').src = link1;" />
            		<img id="link2" src="image2.jpg" onclick="document.getElementById('masterimg').src = link2;" />
            		<img id="link3" src="image3.jpg" onclick="document.getElementById('masterimg').src = link3;" />
            	</body
            </html>

            Comment

            • Joe Strom
              New Member
              • Jul 2011
              • 5

              #7
              Thanks for the example, ill base off that. Any idea how to incorporate form inputs in to change the current src's?

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #8
                This will return the value in a form control.
                Code:
                document.getElementById("FormInputID").value

                Comment

                • Joe Strom
                  New Member
                  • Jul 2011
                  • 5

                  #9
                  I must be doing this completely wrong..?

                  Thanks for all ur help so far, btw.


                  Code:
                  <html>
                      <head>
                          <script type="text/javascript">
                              var link1, link2, link3
                  
                              function loadLinks() {
                                  link1 = document.getElementById("url1").value;
                                  link2 = document.getElementById("link2");
                                  link3 = document.getElementById("link3");
                              }
                          </script>
                      </head>
                  
                      <body onload="loadLinks();">
                          <img id="masterimg" src="image1.jpg" />
                  
                  document.getElementById("FormInputID").value
                          <img id="link1" src="image1.jpg" onclick="document.getElementById('masterimg').src = link1;" />
                          <img id="link2" src="image2.jpg" onclick="document.getElementById('masterimg').src = link2;" />
                          <img id="link3" src="image3.jpg" onclick="document.getElementById('masterimg').src = link3;" />
                  
                  
                  <br><br><br><Br>
                  <form>
                  New URL: <input name="url1" type="text">
                  <br>
                  New URL: <input name="url1" type="text">
                  <br>
                  New URL: <input name="url1" type="text">
                  <br>
                  
                  </form>
                      </body>
                  </html>

                  Comment

                  • Rabbit
                    Recognized Expert MVP
                    • Jan 2007
                    • 12517

                    #10
                    If you're trying to let the user change the image with the form inputs, you haven't done anything to the code to allow for that. You gave all your inputs the same name. Also, you're going to need to use the id attribute as well.

                    Comment

                    Working...