Networking | Hardware | Software | Multimedia | System | Unix&Linux | MBA

Home>>Hardware>>Form code that puts a price relative to an item # in another field

Form code that puts a price relative to an item # in another field

HD Graphics
03-17-2006, 11:49 PM
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 :(

Mr J
03-18-2006, 01:33 PM
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>

Kor
03-18-2006, 02:01 PM
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.


 

TOP

Hyperthreading hurts s
HP sharpens blade PC l
Apple goes for Quad po
Itanium gets scaled do

For more info

HP sharpens blade PC l
Hyperthreading hurts s
can not call click() i
script does not work o
smart menu 
write to an html file 
FireFox doesn't recogn
Changing e.keyCode (e.
Clearing a range creat
UPDATE: My mouse over 

News Archive

onChange Help 
beforeload? vs onload.
Problem with document.
decreasing my javascri
Problem with \\ and \ 
how to stop scrolling?
Change Label Text Colo
Can I forward a page b
2 javascript functions
Validating a textbox 

Related stories:

javascript and layers
Multiple functions with "onload" does not work.
Forcing User to Scroll through Text Box
Confirm delete in href of display:column tag
onChange="submit()" for select only works once
Pop Up Javascript
Call function when user closes browser
Disabling F1, F3, etc. default actions
Link to root

Copyright@2004-2005 www.zzcoke.com All Right Reserved

advanced web statistics