Reputation: 1457
I have a dropdown, which is like so:
<select name="material>
<option value="1">Wood</option>
<option value="2">Metal</option>
<option value="3">Plastic</option>
</select>
Now based on the selection usind the value(id) I would like to update the price on the page using javascript (ie with posting). The values in the dropdown are the id for the material, I do have access to the price on the page as all of these details are returned as an array. Any help with this would be appreciated.
Thanks
Upvotes: 0
Views: 983
Reputation: 78006
This should work for you:
var price = new Array('','$12.00','$18.00','$0.89');
$(function(){
$('select[name=material]').change(function(){
alert(price[$(this).val()]);
});
// Trigger on dom ready
$('select[name=material]').change();
});
Upvotes: 1