...

View Full Version : combobox output



orangelightwhy
01-03-2013, 06:10 PM
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"

AndrewGSW
01-04-2013, 02:09 AM
This is really a JavaScript question, but in essence:


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

felgall
01-04-2013, 05:48 AM
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):


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


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

orangelightwhy
01-05-2013, 12:12 AM
How would i make it go to the image when you click it



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum