Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-03-2013, 05:10 PM   PM User | #1
orangelightwhy
New to the CF scene

 
Join Date: Jan 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
orangelightwhy is an unknown quantity at this point
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"
orangelightwhy is offline   Reply With Quote
Old 01-04-2013, 01:09 AM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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
AndrewGSW is offline   Reply With Quote
Old 01-04-2013, 04:48 AM   PM User | #3
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,530
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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/
felgall is offline   Reply With Quote
Old 01-04-2013, 11:12 PM   PM User | #4
orangelightwhy
New to the CF scene

 
Join Date: Jan 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
orangelightwhy is an unknown quantity at this point
How would i make it go to the image when you click it
orangelightwhy is offline   Reply With Quote
Reply

Bookmarks

Tags
html

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:08 AM.


Advertisement
Log in to turn off these ads.