Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Location
    Currently Phila, PA
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Can't display an Image based on a VAR

    I'm trying to debug a script that I added to which asks a multiple-choice question based on the image displayed. The question and choices come up and eveything works fine except the image is not displayed. Any help?

    Inside the <javascript> tags are three pertinent lines:

    var picture = new Image();

    picture[1] = "lynda005.jpg"
    picture[2] = “jenny009.jpg” etc…

    document.mc.cp.value=picture[NextQ ]

    And in a Form:

    <img name="cp" width="350" height="450" value="">

  • #2
    New to the CF scene
    Join Date
    Aug 2007
    Location
    Currently Phila, PA
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I just figured it out...it should be:

    document.mc.cp.src=picture[NextQ ]
    and not
    document.mc.cp.value=picture[NextQ ]

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    var picture = new Image();
    picture[1] = "lynda005.jpg"
    Arrays start at [0]

    And in a Form:
    <img name="cp" width="350" height="450" value="">
    That is not valid form input code

    Here's and example
    Code:
    <script type="text/javascript">
    window.onload = function() {
    var picture = [
                   ['lynda005.jpg'],
                   ['jenny009.jpg'],
                   ['jenny010.jpg']  // no comma needed after last member
                  ];
    document.getElementById('cp').src = picture[0]; // change 'cp' image src to first member
    document.getElementById('txt').value = picture[1]; // send 2nd member to text field
    }
    </script>
    
    <img id="cp" width="350" height="450" alt="" src="lynda004.jpg" />
    
    <input type="text" id="txt" value="" />


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •