PHP ver gevorderde |
|
Nouja, als het goed is bevat de input sowieso al alleen 0-9.
Het gaat om de onderstaande code (javascript is niet mijn ding, dus sorry als het een beetje inefficient is, kritiek is welkom. en die text/prices ga ik nog ophalen mbv json).
<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>
|