How Do I Make A Drop Down List Selection Update An Image On A Web Page?
Solution 1:
The code on that site is all client-side, and is fairly simple.
You click the link, it invokes Javascript that shows the selection popup div.
When you select an item on the selection popup div, it also calls Javascript. That javascript modifies:
- The original div's label text for the amount field (i.e. the big
€
) - The text below that describes your currently selected currency type (the one that pops up the div)
- The data in the hidden form field, with the selected currency type
...and closes the popup div.
Edit: Apparently you also need the jQuery library in order to use the code in my answer :) You could substitute your own Javascript code, and get identical results, but it wouldn't look exactly like the code below.
Here is the code, ripped straight off "view source":
The amount box:
<divclass="amt_box bg_white"><labelclass="currency-display">$</label><inputtype="text"name="Funds[goalamount]"value=""class="big-field"tabindex="1" /></div>
The link that opens the popup div:
<h4>Display: <ahref="#"class="currency-select">US Dollars</a></h4>
The popup div:
<divclass="currency currency-select-div"style="position:absolute; display:none;margin-left:45px;"><ul><li><ahref="#"class="currency-item"title="$"code="USD">$ USD Dollar</a></li><li><ahref="#"class="currency-item"title="$"code="CAD">$ CAD Dollar</a></li><li><ahref="#"class="currency-item"title="$"code="AUD">$ AUD Dollar</a></li><li><ahref="#"class="currency-item"title="£"code="GBP">£ GBP Pound</a></li><li><ahref="#"class="currency-item"title="€"code="EUR">€ EUR Euro</a></li></ul></div>
The hidden form field:
<inputtype="hidden"id="currencyfield" value="USD" name="Organizations[currencycode]" />
The Javascript (jQuery) code that binds it all together:
$('.currency-select').click(function() {
$('.currency-select-div').show();
returnfalse;
});
$('.currency-item').click(function() {
$('.currency-select-div').hide();
$('.currency-display').text($(this).attr('title'));
$('.currency-select').text($(this).text());
$('#currencyfield').val($(this).attr('code'));
Solution 2:
You're going to want to uniquely identify the text that you're trying to change with your drop-down list first.
<span id="currencySymbol">$</span>
Then you're going to want to create a drop-down list that has the values you want.
<selectid="currencySelect"><optionvalue="$">Dollars</option><optionvalue="£">Pounds</option><optionvalue="€">Euros</option></select>
Then you need to use JavaScript to change the value of the text based on the value of the drop-down.
document.getElementById('currencySelect').onchange = function(){
document.getElementById('currencySymbol').innerHTML = this.value;
}
Post a Comment for "How Do I Make A Drop Down List Selection Update An Image On A Web Page?"