I am a Freelance designer trying to do the following.
I have an item# dropdown box. I am trying to figure out a way such that depending on which item number is selected... the respective price is placed into a quantity field.
Is this even possible without having to implement a database. I have limited knowledge of javascript programming and even less of database! sorry :(
Here's one possibility
<form name="myform">
<select onchange="document.myform.t1.value=this.options[selectedIndex].value">
<option value="0">Select
<option value="1">1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
</select>
<input type="text" name="t1" value="">
</form>
onchange="document['myform']['t1'].value=this.value">
would be enough , as if the list is not a multiple one, select's value is always the selected option's value.
HD Graphics
03-19-2006, 06:01 AM
Thanks for your help, it worked great however now I have run into another small problem....I'll try to explain this clearly:
Alright so what I ahve is a wholesale form where a company logs in and can order however many items they wish at a cheaper price. I have the form set up with the item number auto-filling the price field (thanks to you). I also have some Javascript that is totalling the price times the quantity and placing it in a Total box. This all works great unless once the calculation is done I go back and change the item number..... Then the Total price remains the same.
I am guessing I need some sort of conditional statement that is saying if any field/selection changes then recalculate. Here is the script for the functions I am using...
<script type="text/javascript">
<!-- Begin
function itemTotal(rowNum){
var quantity = "quantity" + rowNum;
var price = "unitPrice" + rowNum;
var total = "TotalBox" + rowNum;
var rowQuantity = document.getElementById(quantity).value;
var rowPrice = document.getElementById(price).value;
document.getElementById(total).value = (rowQuantity * rowPrice).toFixed(2);
productTotal();
}
function productTotal(){
var totalRows = document.getElementById('hiddenTotalRows').value;
var rowTotal, rowTotalValue;
var runningTotal = 0;
for (var i = 1; i <= totalRows; i++){
rowTotal = "TotalBox" + i;
rowTotalValue = document.getElementById(rowTotal).value;
if(parseFloat(document.getElementById(rowTotal).value)){
runningTotal = runningTotal +
parseFloat(document.getElementById(rowTotal).value);
}
}
document.getElementById('orderTotal').value = runningTotal.toFixed(2);
document.getElementById('shipping').value = (runningTotal * .12).toFixed(2);
document.getElementById('grandtotal').value = (runningTotal + runningTotal * .12).toFixed(2);
}
// End -->
</script>
Any help on this issue would be great! Thanks in advance.