Click to See Complete Forum and Search --> : Checkboxes and TextBoxes...


Paulo Monteiro
08-21-2006, 10:56 AM
Greetings at all!!!

I have a problem that I know the reason but I didn't yet discover how to fix it:

In an e-commerce development I show a series of products dinamically and they have a checkbox for select each one if I wan't to buy them. I tried to implement a textbox for input a quantity but I canīt correspond the checkboxes array and the textboxes array. If I substitute the textboxes with checkboxes with diferent values they match. I discuss the issue with a friend and he tell me that the check and text boxes can have diferent sizes. My point is: how can I resolve this for select the products, input a quantity for show the final price?? I need a example because I don't am very good in programming...can you help me??

Kor
08-21-2006, 02:53 PM
Greetings at all!!!

I have a problem that I know the reason but I didn't yet discover how to fix it:

In an e-commerce development I show a series of products dinamically and they have a checkbox for select each one if I wan't to buy them. I tried to implement a textbox for input a quantity but I canīt correspond the checkboxes array and the textboxes array. If I substitute the textboxes with checkboxes with diferent values they match. I discuss the issue with a friend and he tell me that the check and text boxes can have diferent sizes. My point is: how can I resolve this for select the products, input a quantity for show the final price?? I need a example because I don't am very good in programming...can you help me??
I am not quite sure I have understood your problem, but... have u tried lists (select)?

Any way, can u show us a simple example html of what u have and what u want?

JMRKER
08-21-2006, 07:04 PM
I'm not sure from you description, but see if this works for your needs.


<html>
<head>
<title></title>
<script type="text/javascript">
<!--
function Calc() {
var subtotal = 0;
for (i=0; i<=4; i++) {
if (document.getElementById('item'+i).checked) {
subtotal += document.getElementById('item'+i).value * document.getElementById('qty'+i).value;
}
}
document.getElementById('total').value = subtotal;
}
//-->
</script>
</head>
<body>
Item #1 <input type="checkbox" id="item0" value=10>$10.00
<input type="text" id="qty0" value="0" size="5"> Quantity
<br />
Item #2 <input type="checkbox" id="item1" value=20>$20.00
<input type="text" id="qty1" value="0" size="5"> Quantity
<br />
Item #3 <input type="checkbox" id="item2" value=40>$40.00
<input type="text" id="qty2" value="0" size="5"> Quantity
<br />
Item #4 <input type="checkbox" id="item3" value=80>$80.00
<input type="text" id="qty3" value="0" size="5"> Quantity
<br />
Item #5 <input type="checkbox" id="item4" value=100>$100.00
<input type="text" id="qty4" value="0" size="5"> Quantity
<p />
<button onClick="Calc()">Calculate</button>
Total: $<input type="text" id="total" value=0 size="10">
</body>
</html>