开发者

Javascript dropdown updates the price based on the users selection?

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 wo开发者_如何学编程uld 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


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();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜