...

View Full Version : Someone help please



cythrill
05-24-2012, 09:14 PM
wondering if someone can help me with a script , probably will be easy for you, ive been fumbling through it for about 5 hours and i cant figure out what to do, basciall I have 2 drop down menus, one for and item and one for quantity, the script multiplies the item value by the quantity then totals it, I have been trying to add a "Shipping" dropdown in there, but when I put the code in, The Item value, multiplies by the quantiy selected, then multiplies by the shipping amount, I need it to just add the shipping to the subtotal, and for the life of me I just cannot do it, please help! Thanks in advance. This is what i have so far sorry its a little length -

cythrill
05-24-2012, 09:48 PM
I cannot get the Product times quantity plus shipping to work - please help

<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
function doit(sel,qty,sub)
{
var grand = 0;
var temp = sel.options[sel.selectedIndex].value
var temp2 = document.frm.elements[qty].options[document.frm.elements[qty].selectedIndex].value
var temp3 = document.frm.elements[shipping].options[document.frm.elements[shipping].selectedIndex].value
document.frm.elements[sub].value = temp*temp2
for(i=0; i<3; i++) //change i <3 according to the number of sub total boxes u have. if u have 6 sub total change it to i <5
{
grand += document.frm.elements['sub'+i].value*1;
}
document.frm.grand.value = grand;
}

function doit1(qty,sel,sub)
{
var grand =0;
var temp = qty.options[qty.selectedIndex].value
var temp2 = document.frm.elements[sel].options[document.frm.elements[sel].selectedIndex].value
var temp3 = document.frm.elements[shipping].options[document.frm.elements[shipping].selectedIndex].value
document.frm.elements[sub].value = temp*temp2
for(i=0; i<3; i++)//change i <3 according to the number of sub total boxes u have. if u have 6 sub total change it to i <5
{
grand += document.frm.elements['sub'+i].value*1;
}
document.frm.grand.value = grand;
}

var grand =0;
var temp = shipping.options[shipping.selectedIndex].value
var temp2 = document.frm.elements[sel].options[document.frm.elements[sel].selectedIndex].value
var temp3 = document.frm.elements[qty].options[document.frm.elements[qty].selectedIndex].value
document.frm.elements[sub].value = temp+temp2
for(i=0; i<3; i++)//change i <3 according to the number of sub total boxes u have. if u have 6 sub total change it to i <5
{
grand += document.frm.elements['sub'+i].value*1;
}
document.frm.grand.value = grand;
}

</script>
</HEAD>

<BODY>


<form name = "frm">
<select name = "sel" id = "sel" onchange = "doit(this,'qty','sub0')">
<option value="19" >#1006 Deco Daisy - $19.00</option>
<option value="19" >#1007 South Beach - $19.00</option>
<option value="19" >#1008 Book Berry - $19.00</option>
<option value="19" >#1009 Love Story - $19.00</option>
</select>
<select name = "qty" id = "qty" onchange = "doit1(this,'sel','sub0')">
<option value="1" >1</option>
<option value="2" >2</option>
<option value="3" >3</option>
</select>
<select name = "shipping" id = "Shipping" onchange = "doit(this,'qty','sub1')">
<option value="1.95" >$1.95</option>
<option value="5.95" >$5.95</option>
<option value="8.95" >$8.95</option>
<option value="10.95" >$10.95</option>
</select>
<input type = "text" readonly name = "sub0">
<br>
<select name = "sel1" id = "sel1" onchange = "doit(this,'qty1','sub1')">
<option value = "0">select here</option>
<option value="" >Select Product</option>
<option value="19" >#1006 Deco Daisy - $19.00</option>
<option value="19" >#1007 South Beach - $19.00</option>
<option value="19" >#1008 Book Berry - $19.00</option>
<option value="19" >#1009 Love Story - $19.00</option>
</select>
<select name = "qty1" id = "qty1" onchange = "doit1(this,'sel1','sub1')">
<option value="1" >1</option>
<option value="2" >2</option>
<option value="3" >3</option>
</select>
<input type = "text" readonly name = "sub1" >
<br>
<select name = "sel2" id = "sel2" onchange = "doit(this,'qty2','sub2')">
<option value = "0">select here</option>
<option value="" >Select Product</option>
<option value="19" >#1006 Deco Daisy - $19.00</option>
<option value="19" >#1007 South Beach - $19.00</option>
<option value="19" >#1008 Book Berry - $19.00</option>
<option value="19" >#1009 Love Story - $19.00</option>
</select>
<select name = "qty2" id = "qty2" onchange = "doit1(this,'sel2','sub2')">
<option value="1" >1</option>
<option value="2" >2</option>
<option value="3" >3</option>
<option value="4" >4</option>
</select>
<input type = "text" readonly name = "sub2">
<br>
Grand Total:<input type = "text" readonly name = "grand">
</form>

</BODY>
</HTML>

Old Pedant
05-25-2012, 04:06 AM
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script type="text/javascript">
function doit()
{
var form = document.frm;
var grand = 0;
for ( pnum = 1; pnum < 999999; ++pnum )
{
var prod = form["product"+pnum];
if ( prod == null ) break; // out of the for loop when no more products
prod = Number(prod.value);
var qty = Number(form["qty"+pnum].value);
var ship = Number(form["shipping"+pnum].value);

var sub = prod * qty + ship;
form["sub"+pnum].value = sub.toFixed(2);
grand += sub;
}
frm.grand.value = grand.toFixed(2);
}


</script>
</HEAD>

<BODY>


<form name = "frm">
<select name = "product1" onchange = "doit()">
<option value="0">--choose a product--</option>
<option value="19" >#1006 Deco Daisy - $19.00</option>
<option value="19" >#1007 South Beach - $19.00</option>
<option value="19" >#1008 Book Berry - $19.00</option>
<option value="19" >#1009 Love Story - $19.00</option>
</select>
<select name = "qty1" onchange = "doit()">
<option value="1" >1</option>
<option value="2" >2</option>
<option value="3" >3</option>
</select>
<select name = "shipping1" onchange = "doit()">
<option value="1.95" >$1.95</option>
<option value="5.95" >$5.95</option>
<option value="8.95" >$8.95</option>
<option value="10.95" >$10.95</option>
</select>
<input type = "text" readonly name = "sub1">
<br>
<select name = "product2" onchange = "doit()">
<option value="0">--choose a product--</option>
<option value="19" >#1006 Deco Daisy - $19.00</option>
<option value="19" >#1007 South Beach - $19.00</option>
<option value="19" >#1008 Book Berry - $19.00</option>
<option value="19" >#1009 Love Story - $19.00</option>
</select>
<select name = "qty2" onchange = "doit()">
<option value="1" >1</option>
<option value="2" >2</option>
<option value="3" >3</option>
</select>
<select name = "shipping2" onchange = "doit()">
<option value="1.95" >$1.95</option>
<option value="5.95" >$5.95</option>
<option value="8.95" >$8.95</option>
<option value="10.95" >$10.95</option>
</select>
<input type = "text" readonly name = "sub2">
<br>
<select name = "product3" onchange = "doit()">
<option value="0">--choose a product--</option>
<option value="19" >#1006 Deco Daisy - $19.00</option>
<option value="19" >#1007 South Beach - $19.00</option>
<option value="19" >#1008 Book Berry - $19.00</option>
<option value="19" >#1009 Love Story - $19.00</option>
</select>
<select name = "qty3" onchange = "doit()">
<option value="1" >1</option>
<option value="2" >2</option>
<option value="3" >3</option>
</select>
<select name = "shipping3" onchange = "doit()">
<option value="1.95" >$1.95</option>
<option value="5.95" >$5.95</option>
<option value="8.95" >$8.95</option>
<option value="10.95" >$10.95</option>
</select>
<input type = "text" readonly name = "sub3">
<br>
<br>
Grand Total:<input type = "text" readonly name = "grand">
</form>

</BODY>
</HTML>

Notice that the code automatically adjusts for any number of products.

Normally, shipping is added PER ORDER, not per item. But I left it as you had it.

Old Pedant
05-25-2012, 05:24 AM
iBall's answer is correct, of course, but I suspect it may be too advanced for you to follow.

If so, it's easy to change my code to get rid of the bogus shipping costs:

Just change this one line:


var sub = prod * qty + ship;

to this:


var sub = prod * qty;
if ( sub == 0 ) sub += ship;

Old Pedant
05-25-2012, 07:40 PM
Naturally, that should have been != 0 instead of == 0.

Just a typo.

iBall could have pointed that out but of course he prefers to make a big deal over little things.

Nothing ever changes, does it Bullant?

Don't you lie awake nights trying to remember which person you are supposed to be tomorrow, Mishu?

Wouldn't you *PLEASE* put me back on your ignore list? It was much quieter then.

Philip M
05-26-2012, 08:02 AM
The great advantage of being on iBall's ignore list is that, although many of his posts simply repeat what has already been said, he cannot seize on something in one of my posts to start a pointless and belligerent argument, or sneer at an accidental typo :p



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum