<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
<!--
function count(f,n,u)
{
document.form1.subt[n].value = document.form1.qty[n].value * u ;
var st = 0;
for(i=0; i < document.form1.subt.length; i++)
{
st += Math.ceil(document.form1.subt[i].value * 1000) /1000
}
document.form1.sub_total.value = "$ " + st;
}
function CalcuTotal() {
var gifty= document.getElementById(qty[0]);
document.form1.total.value= gifty * document.form1.gift.value;
}
// -->
</script>
</head>
<body>
<form name="form1" method="post" action="" >
<table border="2"><tbody>
<tr><td colspan="3"><b>Order Form</b></td></tr><tr>
<td width="144"><u>Qty</u></td>
<td width="143"><u>Items</u></td><td width="531"><u>Total</u></td></tr>
<tr>
<td><input name="qty" id="qty1" type="text" value="0" onkeyup="count(this.form,0,10.00)"/></td>
<td>A-$10.00</td>
<td><input name="subt" type="text" readonly="readonly"/></td></tr>
<tr >
<td><input name="qty" id="qty2" type="text" value="0" onkeyup="count(this.form,1,9.99)" /></td>
<td>B-$9.99</td>
<td><input name="subt" type="text" readonly="readonly"/></td></tr>
<tr>
<td><input name="qty" id="qty3" type="text" value="0" onkeyup="count(this.form,2,12.99)"/></td>
<td>C-$ 15.99</td>
<td><input name="subt" type="text" readonly="readonly"/></td>
</tr>
<tr>
<td><input name="qty" type="text" value="0" onkeyup="count(this.form,3,10.00)"/></td>
<td>D-$10.00</td>
<td><input name="subt" type="text" readonly="readonly"/></td>
</tr>
<tr>
<td><input name="qty" type="text" value="0" onkeyup="count(this.form,4,12.00)" /></td>
<td>E-$12.00</td>
<td><input name="subt" type="text" readonly="readonly" /></td></tr>
<tr>
<td><input name="qty" type="text" value="0" onkeyup="count(this.form,5,3.99)" /></td>
<td>F-$3.00</td>
<td><input name="subt" type="text" readonly="readonly" /></td>
</tr>
<tr >
<td colspan="2">Subtotal</td>
<td><input name="sub_total" type="text" size="10" readonly="readonly" /></td></tr>
<tr >
<td colspan="3"><label>
<input type="checkbox" name="gift" id="gift" value="2.00"
onclick="calcuTotal()" />
Gift wrapping? (extra of $2.00 per box)<br />
gift card text:<br />
<textarea name="note" id="note" cols="45" rows="5" ></textarea>
</label></td>
</tr>
<tr >
<td colspan="2"><p>shiping and handling</p></td>
<td>$3.00 for 1-3 boxes, $ 5.00 for 3 plus boxes</td>
</tr>
<tr >
<td colspan="2">Total</td>
<td><label>
<input type="text" name="total" id="total" readonly="readonly"/>
</label></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
Form doesn't work (I'm trying to learn)
Page 1 of 114 Replies - 3254 Views - Last Post: 11 April 2011 - 09:17 AM
#1
Form doesn't work (I'm trying to learn)
Posted 07 April 2011 - 05:09 PM
Replies To: Form doesn't work (I'm trying to learn)
#2
Re: Form doesn't work (I'm trying to learn)
Posted 07 April 2011 - 05:36 PM
The individual calculations are working but the total value is not getting calculated.
#3
Re: Form doesn't work (I'm trying to learn)
Posted 07 April 2011 - 06:26 PM
#4
Re: Form doesn't work (I'm trying to learn)
Posted 07 April 2011 - 06:48 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
<!--
function count(f,n,u)
{
document.form1.subt[n].value = document.form1.qty[n].value * u ;
var st = 0;
for(i=0; i < document.form1.subt.length; i++)
{
st += Math.ceil(document.form1.subt[i].value * 1000) /1000
}
document.form1.sub_total.value = "$ " + st;
}
// -->
</script>
</head>
<body>
<form name="form1" method="post" action="" >
<table border="2"><tbody>
<tr><td colspan="3"><b>Order Form</b></td></tr><tr>
<td width="144"><u>Qty</u></td>
<td width="143"><u>Items</u></td><td width="531"><u>Total</u></td></tr>
<tr>
<td><input name="qty" type="text" value="0" onkeyup="count(this.form,0,10.99)"/></td>
<td>A-$10.00</td>
<td><input name="subt" type="text" readonly="readonly"/></td>
</tr>
<tr >
<td><input name="qty" type="text" value="0" onkeyup="count(this.form,1,9.99)" /></td>
<td>B-$9.99</td>
<td><input name="subt" type="text" readonly="readonly"/></td>
</tr>
<tr >
<td colspan="2">Subtotal</td>
<td><input name="sub_total" type="text" size="10" readonly="readonly" /></td>
</tr>
<tr >
<td colspan="3"><label>
<input type="checkbox" name="gift" id="gift" value="1.95"
onclick=")" />
Gift wrapping? (extra of $2.00 per box)<br />
gift card text:<br />
<textarea name="note" id="note" cols="45" rows="5" ></textarea>
</label></td>
</tr>
<tr >
<td colspan="2"><p>shiping and handling</p></td>
<td>$3.00 for 1-3 boxes, $ 5.00 for 3 plus boxes</td>
</tr>
<tr >
<td colspan="2">Total</td>
<td><label>
<input type="text" name="total" id="total" readonly="readonly"/>
</label></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
#5
Re: Form doesn't work (I'm trying to learn)
Posted 07 April 2011 - 06:58 PM
So create another function that gets a reference to the checkbox, uses its "checked" property to determine if it is checked or not and depending on its state, you add or remove the 2.00 from the subtotal box.
If there is something else not working, please let us know "IN ADDITION" to your code.
#6
Re: Form doesn't work (I'm trying to learn)
Posted 07 April 2011 - 07:27 PM
I wonder how I could multiply qty * gift wrap check( check box). I tried to do it within count(f,n,u), but it didn't work.
Do I have to create two functions?
#7
Re: Form doesn't work (I'm trying to learn)
Posted 07 April 2011 - 07:52 PM
Also you will want to keep track of how much you have added to the subtotal in the way of gift boxes because you may need to subtract that value back out if they reduce the number of boxes or simply uncheck the box.
Never be afraid of breaking a problem into separate functions. The sooner you get into the habit of breaking a problem down into smaller functions, the better off you will be later. Newbies always want to put all their code into one function and try to do too many things at once. That is where they run into trouble later.
#8
Re: Form doesn't work (I'm trying to learn)
Posted 08 April 2011 - 10:52 AM
Do I have to assign a new ID to qty in order to use it in another function?
#9
Re: Form doesn't work (I'm trying to learn)
Posted 08 April 2011 - 12:17 PM
#10
Re: Form doesn't work (I'm trying to learn)
Posted 10 April 2011 - 01:25 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
<!--
function count(n,u){
document.form1.subt[n].value = document.form1.qty[n].value * u ;
st = 0;
for(i=0; i < document.form1.subt.length; i++)
{
st += Math.ceil(document.form1.subt[i].value * 1000) /1000
}
document.form1.sub_total.value = "$ " + st;
quantity()
giftCheck()
tc()
}
function quantity() {
var first= parseFloat (document.form1.qty[0].value);
var sec = parseFloat (document.form1.qty[1].value);
var qfinal= first + sec;
return qfinal
tc()
}
function shipping (){
var shipRate1= 3
var shipRate2= 5
if (quantity() < 3) {
return shipRate1
}else{
return shipRate2
}
}
function giftCheck() {
rate= document.form1.gift.value * quantity();
return rate
tc()
}
function tc() {
subtt = document.form1.sub_total.value;
gf= giftCheck();
shipt= shipping();
misce= subtt + gf + shipt;
document.form1.total.value = misce ;
}
// -->
</script>
</head>
<body>
<form name="form1" method="post" action="" >
<table border="2"><tbody>
<tr><td colspan="3"><b>Order Form</b></td></tr><tr>
<td width="144"><u>Qty</u></td>
<td width="143"><u>Items</u></td><td width="531"><u>Total</u></td></tr>
<tr>
<td><input name="qty" id="A" type="text" value="0" onkeyup="count(0,10.99)"/></td>
<td>A-$10.00</td>
<td><input name="subt" type="text" readonly="readonly"/></td>
</tr>
<tr >
<td><input name="qty" id= "B" type="text" value="0" onkeyup="count(1,9.99)" /></td>
<td>B-$9.99</td>
<td><input name="subt" type="text" readonly="readonly"/></td>
</tr>
<tr >
<td colspan="2">Subtotal</td>
<td><input name="sub_total" type="text" size="10" readonly="readonly" /></td>
</tr>
<tr >
<td colspan="3"><label>
<input type="checkbox" name="gift" id="gift" value="2.00"
onclick="giftCheck()" />
Gift wrapping? (extra of $2.00 per box)<br />
gift card text:<br />
<textarea name="note" id="note" cols="45" rows="5" ></textarea>
</label></td>
</tr>
<tr >
<td colspan="2"><p>shiping and handling</p></td>
<td>$3.00 for 1-3 boxes, $ 5.00 for 3 plus boxes</td>
</tr>
<tr >
<td colspan="2">Total</td>
<td><label>
<input type="text" name="total" id="total" readonly="readonly"/>
</label></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
#11
Re: Form doesn't work (I'm trying to learn)
Posted 10 April 2011 - 01:37 PM
The total field is getting calculated correctly, though the Giftbox option is not working.
Post exact errors.
This post has been edited by nandureddy: 10 April 2011 - 01:37 PM
#12
Re: Form doesn't work (I'm trying to learn)
Posted 10 April 2011 - 01:49 PM
nandureddy, on 10 April 2011 - 01:37 PM, said:
The total field is getting calculated correctly, though the Giftbox option is not working.
Post exact errors.
I meant the second total or grand total at the end of the form. It shows concatenated strings instead of a sum.
#13
Re: Form doesn't work (I'm trying to learn)
Posted 10 April 2011 - 10:27 PM
#14
Re: Form doesn't work (I'm trying to learn)
Posted 11 April 2011 - 07:24 AM
This post has been edited by Dormilich: 11 April 2011 - 07:24 AM
#15
Re: Form doesn't work (I'm trying to learn)
Posted 11 April 2011 - 09:17 AM
Dormilich, on 11 April 2011 - 07:24 AM, said:
Thank you for your help.
Now the form adds the check box value even if it's not selected. I have used the following functions, but it didn't worked:
function wrap() {
if (document.form1.gift.checked)
return document.form1.gift.value
}
function wrap () {
x= document.form1.gift.value * quantity();
return x
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
<!--
function count(n,u){
document.form1.subt[n].value = document.form1.qty[n].value * u ;
st = 0;
for(i=0; i < document.form1.subt.length; i++)
{
st += Math.ceil(document.form1.subt[i].value * 1000) /1000
}
document.form1.sub_total.value = "$" + st;
quantity()
tc()
}
function quantity() {
var first= parseFloat (document.form1.qty[0].value);
var sec = parseFloat (document.form1.qty[1].value);
var qfinal= first + sec;
return qfinal
wrap()
tc()
}
function shipping (){
var shipRate1= 3
var shipRate2= 5
if (quantity() < 3) {
return shipRate1
}else{
return shipRate2
}
}
function wrap() {
if (document.form1.gift.checked)
return document.form1.gift.value
}
function wrap () {
x= document.form1.gift.value * quantity();
return x
}
function tc() {
subtt= document.form1.sub_total.value;
gf= wrap();
ship= shipping();
subtt= subtt.slice(1);
misce= Number(subtt) + ship + gf ;
document.form1.total.value = "$" + misce;
}
// -->
</script>
</head>
<body>
<form name="form1" method="post" action="" >
<table border="2"><tbody>
<tr><td colspan="3"><b>Order Form</b></td></tr><tr>
<td width="144"><u>Qty</u></td>
<td width="143"><u>Items</u></td><td width="531"><u>Total</u></td></tr>
<tr>
<td><input name="qty" id="A" type="text" value="0" onkeyup="count(0,10.99)"/></td>
<td>A-$10.00</td>
<td><input name="subt" type="text" readonly="readonly"/></td>
</tr>
<tr >
<td><input name="qty" id= "B" type="text" value="0" onkeyup="count(1,9.99)" /></td>
<td>B-$9.99</td>
<td><input name="subt" type="text" readonly="readonly"/></td>
</tr>
<tr >
<td colspan="2">Subtotal</td>
<td><input name="sub_total" type="text" size="10" readonly="readonly" /></td>
</tr>
<tr >
<td colspan="3"><label>
<input type="checkbox" name="gift" id="gift" value="2"
onclick="wrap()" />
Gift wrapping? (extra of $2.00 per box)<br />
gift card text:<br />
<textarea name="note" id="note" cols="45" rows="5" ></textarea>
</label></td>
</tr>
<tr >
<td colspan="2"><p>shiping and handling</p></td>
<td>$3.00 for 1-3 boxes, $ 5.00 for 3 plus boxes</td>
</tr>
<tr >
<td colspan="2">Total</td>
<td><label>
<input type="text" name="total" id="total" readonly="readonly"/>
</label></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
This post has been edited by novato1: 11 April 2011 - 09:19 AM
|
|

New Topic/Question
Reply


MultiQuote





|