homepage Welcome to WebmasterWorld Guest from 23.22.173.58
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Drop-down running total
tigerfrog



 
Msg#: 4380180 posted 2:07 pm on Oct 27, 2011 (gmt 0)

Hi all,

I've been struggling for a fews days to get code to work so I thought it might be time to ask for some help.

My site currently has multiple drop-downs that give a running price total at the bottom. This is javascript.

I use RomantCart product manager for my products and want to combine the 2 so that I have a running total and then an add to cart button at the end.

This page here shows the 2 working independantly:
[tigerfrog.co.uk ] the second set of dropdowns aren't presented well or hold the right info, but they give the idea.

The running total uses javascript but the add to cart is html. What I've been trying to do is combine the 2, but to make this work I need 2 values from each option - one for the running total, and one for the final add to cart.

The javascript code is:

header:
<script language="JavaScript" type="text/javascript">

function calc2(){
var totalStr = ''; // for testing only
var totalValue=0;
var DDL;
var cnt = 0; // for testing only
for (var j=1; j<=9; j++) {
DDL = document.getElementById('dropDownList'+j);
temp = DDL.options[DDL.selectedIndex].value;
totalValue += Number(temp);
if (DDL.selectedIndex != 0) { totalStr += '|'+temp; cnt++; } // cnt++ is for testing only
}
document.forms[0].total.value=totalValue;
}
</script>


body:
<form id="dropDownForm2" name="dropDownForm2">
<tbody class="style10">
<tr>
<td class="style48" style="width: 70px" valign="left" valign="top">
Frameset</td>
<td class="style14">&nbsp;<select id="dropDownList1" class="style10" name="D10" onchange="calc2();" style="width: 300px">
<option href="alloy.htm" selected="" value="471">
TF100 Alloy</option>
<option value="1004">TF300C Carbon</option>
<option value="1097">TF400C Carbon **Available
Now**</option>
</select> </td>
</tr>
<tr>
<td align="left" class="style48" style="width: 70px" valign="top">
Groupset</td>
<td class="style14">&nbsp;<select id="dropDownList2" class="style10" name="D11" onchange="calc2();" style="width: 300px">
<option>---------Shimano---------</option>
<option selected="selected" value="263">Shimano
Sora 3400 TT 9sp</option>
<option value="306">Shimano Tiagra 4500 TT 9sp
</option>
<option value="365">Shimano 105 5600 TT
</option>

</select> </td>
</tr>
<tr>
<td align="left" class="style48" style="width: 70px" valign="top">
Wheelset</td>
<td class="style14">&nbsp;<select id="dropDownList3" class="style10" name="D12" onchange="calc2();" style="width: 300px">
<option>-------Alloy-------</option>
<option selected="" value="100">Miche Excite
</option>
<option value="148">Campagnolo Khamsin
</option>

</select> </td>
</tr>
<tr>
<td align="left" class="style48" style="width: 70px" valign="top">
Saddle</td>
<td class="style14">&nbsp;<select id="dropDownList4" class="style10" name="D13" onchange="calc2();" style="width: 300px">
<option selected="" value="56">Selle Italia
SL T1</option>
<option value="96">Selle Italia SLR Tri Gel
</option>
<option value="105">ISM Adomo Road 2
</option>

</select> </td>
</tr>
<tr>
<td align="left" class="style48" style="width: 70px" valign="top">
Handlebars</td>
<td class="style14">&nbsp;<select id="dropDownList5" class="style10" name="D14" onchange="calc2();" style="width: 300px">
<option>-------Alloy-------</option>
<option selected="" value="53">Token TT Alloy
</option>
<option value="84">Deda Crononero/ Parabolica
Alloy</option>
<option value="145">Profile Design Synop TT
Aero Alloy</option>

</select> </td>
</tr>
<tr>
<td align="left" class="style48" style="width: 70px" valign="top">
Tyres</td>
<td class="style14">&nbsp;<select id="dropDownList6" class="style10" name="D15" onchange="calc2();" style="width: 300px">
<option>-------Clincher-------</option>
<option selected="" value="15">Zaffiro
</option>
<option value="23">Vittoria Rubino</option>
<option value="43">Vittoria Rubino Pro
</option>

</select> </td>
</tr>
<tr>
<td align="left" class="style48" style="width: 70px" valign="top">
Fininshing*</td>
<td class="style14">&nbsp;<select id="dropDownList7" class="style10" name="D16" onchange="calc2();" style="width: 300px">
<option selected="" value="0">Standard Finishing
Kit</option>
<option value="35">Pro Finishing Kit for Alloy
frames</option>
<option value="101">Elite Finishing Kit for
Carbon frames</option>
</select> </td>
</tr>
<tr>
<td align="left" class="style48" style="width: 70px" valign="top">
Pedals</td>
<td class="style14">&nbsp;<select id="dropDownList8" class="style10" name="D17" onchange="calc2();" style="width: 300px">
<option selected="" value="0">Pedals - Optional
</option>
<option value="31">Shimano R540 SPD-SL
</option>

</select> </td>
</tr>
<tr>
<td align="left" class="style14" style="width: 70px" valign="top">
Powermeter</td>
<td class="style14">&nbsp;<select id="dropDownList9" class="style10" name="D18" onchange="calc2();" style="width: 300px">
<option selected="" value="0">Powermeter - Optional
</option>
<option value="595">Powertap Elite+ w/o CPU
</option>

</select> </td>
</tr>
<tr>
<td class="style48" style="width: 70px" valign="top">&nbsp;</td>
<td class="style10" valign="top">
<span class="style2">&nbsp;&nbsp;&nbsp;&nbsp;
Total Value&nbsp; </span>&nbsp;<input class="style10" name="total" onfocus="blur()" readonly="" size="4" style="width: 46px; height: 22px;" type="text" value="958" />
</td>
</tr>
</tbody>
</form>


the code for the product manager add to cart is html and as follows:
<form action='http://www.romancart.com/cart.asp' method='post'>
<input type='hidden' name='storeid' value='43579'>
<input type='hidden' name='itemcode' value='TF Series'>
Frameset <select name='itemname2'><option value='TF100'>TF100</option><option value='TF300C'>TF300C</option><option value='TF400C'>TF400C</option></select><br>
Groupset <select name='itemname3'><option value='Tiagra'>Tiagra</option><option value='105'>105</option><option value='Ultegra'>Ultegra</option><option value='Dura Ace'>Dura Ace</option></select><br>
Wheelset <select name='itemname4'><option value='Miche Excite'>Miche Excite</option><option value='Fulcrum Racing 7'>Fulcrum Racing 7</option></select><br>
Saddle <select name='itemname5'><option value='SL T1'>SL T1</option><option value='SLR T1'>SLR T1</option></select><br>
Handle Barss <select name='itemname6'><option value='aa'>aa</option><option value='bb'>bb</option></select><br>
Tyres <select name='itemname7'><option value='cc'>cc</option><option value='dd'>dd</option></select><br>
Finishing Kit <select name='itemname8'><option value='std'>std</option><option value='pro'>pro</option></select><br>
Pedals <select name='itemname9'><option value='ff'>ff</option><option value='gg'>gg</option></select><br>
Power Meter <select name='itemname10'><option value='Powertap 1'>Powertap 1</option><option value='powertap 2'>powertap 2</option></select><br>
<input type='submit' value='Add to basket'>
</form>


I've cut a lot of the options out to keep the code shorter, but hopefully it gives a good idea of what I'm looking for and what code I have so far.

The product manager code is short and sharp and I've being trying to use the javascprit script in the head and then the select lines form the javascript code dropped into the product manager scprit lines - but I'm stuck when I need 2 values

Any help here will be fantastic

Phil

 

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved