PHP ver gevorderde |
|
Ik ben zojuist op het idee gekomen om de "value" te gaan gebruiken als array key.
<script type="text/javascript">
var memoryText = new Array("256 MB", "512 MB", "1024 MB", "2048 MB", "4096 MB", "8192 MB", "16384 MB");
var memoryPrice = new Array("1.00", "2.00", "4.00", "5.50", "10.00", "20.00", "35.00");
var harddiskText = new Array("5 GB", "10 GB", "25 GB", "50 GB", "100 GB", "250 GB", "500 GB", "1 TB");
var harddiskPrice = new Array("0.50", "1.00", "2.00", "4.00", "7.50", "15.00", "27.50", "40.00");
$(function() {
function calculateTotalPrice() {
$("#totalPrice").val(eval($("#memoryPrice").val())+eval($("#harddiskPrice").val()));
}
$("#memorySlider").slider({
value:0,
min: 0,
max: memoryText.length-1,
step: 1,
slide: function(event, ui) {
$("#memoryText").val(memoryText[ui.value]);
$("#memoryPrice").val(memoryPrice[ui.value]);
calculateTotalPrice();
}
});
$("#harddiskSlider").slider({
value:0,
min: 0,
max: harddiskText.length-1,
step: 1,
slide: function(event, ui) {
$("#harddiskText").val(harddiskText[ui.value]);
$("#harddiskPrice").val(harddiskPrice[ui.value]);
calculateTotalPrice();
}
});
$("#memoryText").val(memoryText[$("#memorySlider").slider("value")]);
$("#memoryPrice").val(memoryPrice[$("#memorySlider").slider("value")]);
$("#harddiskText").val(harddiskText[$("#harddiskSlider").slider("value")]);
$("#harddiskPrice").val(harddiskPrice[$("#harddiskSlider").slider("value")]);
calculateTotalPrice();
});
</script>
<script type="text/javascript"> var memoryText = new Array("256 MB", "512 MB", "1024 MB", "2048 MB", "4096 MB", "8192 MB", "16384 MB"); var memoryPrice = new Array("1.00", "2.00", "4.00", "5.50", "10.00", "20.00", "35.00"); var harddiskText = new Array("5 GB", "10 GB", "25 GB", "50 GB", "100 GB", "250 GB", "500 GB", "1 TB"); var harddiskPrice = new Array("0.50", "1.00", "2.00", "4.00", "7.50", "15.00", "27.50", "40.00"); $(function() { function calculateTotalPrice() { $("#totalPrice").val(eval($("#memoryPrice").val())+eval($("#harddiskPrice").val())); } $("#memorySlider").slider({ value:0, min: 0, max: memoryText.length-1, step: 1, slide: function(event, ui) { $("#memoryText").val(memoryText[ui.value]); $("#memoryPrice").val(memoryPrice[ui.value]); calculateTotalPrice(); } }); $("#harddiskSlider").slider({ value:0, min: 0, max: harddiskText.length-1, step: 1, slide: function(event, ui) { $("#harddiskText").val(harddiskText[ui.value]); $("#harddiskPrice").val(harddiskPrice[ui.value]); calculateTotalPrice(); } }); $("#memoryText").val(memoryText[$("#memorySlider").slider("value")]); $("#memoryPrice").val(memoryPrice[$("#memorySlider").slider("value")]); $("#harddiskText").val(harddiskText[$("#harddiskSlider").slider("value")]); $("#harddiskPrice").val(harddiskPrice[$("#harddiskSlider").slider("value")]); calculateTotalPrice(); }); </script>
Dit lijkt me een best handige manier en ga ik verder uitwerken. |