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 4 of 4

Thread: combobox output

  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question combobox output

    I need to make a thing of when the user selects an item in a combobox it changes it in the url of a picturebox box.
    so if you select Red Apple in the combobox the picturebox src would be "www.help.com/rapple"
    if you select Green Apple in the combobox the picturebox src would be "www.help.com/gapple"

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    This is really a JavaScript question, but in essence:

    Code:
    <select onchange="updatePicture(this)">
    
    
    <script type="text/javascript">
    function updatePicture(oSelect) {
        var chosenVal = oSelect.options[oSelect.selectedIndex].value;
        var pic = document.getElementById('pictureboxid');
        if (chosenVal == 'Red Apple') {
            pic.src = "www.help.com/rapple.gif";
        } else if (chosenVal == 'Green Apple') {
            pic.src = "www.help.com/gapple.gif";
        }
    }
    </script>
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,620
    Thanks
    0
    Thanked 645 Times in 635 Posts
    What image do you intend to display if someone enters a value into the combo box that doesn't have a corresponding image - or did you mean a select list rather than a combo box.

    Combo Box (where someone can select an option from the list or type their own):

    Code:
    <input type="text" list="fruit">
    <datalist id="fruit">
    <option value="Red Apple">Red Apple</option>
    <option value="Green Apple">Green Apple</option>
    </datalist>
    Select List:

    Code:
    <select>
    <option value="Red Apple">Red Apple</option>
    <option value="Green Apple">Green Apple</option>
    </select>
    Two completely different field types (although Andrew's JavaScript would work for both apart from needing an extra else for a combobox to cater for when the person enters "Purple Pears" or "Yellow Bananas" or "qwertyuiop".
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #4
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How would i make it go to the image when you click it


  •  

    Tags for this Thread

    Posting Permissions

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