473,287 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

I need to calculate the total using javascript where i use 3 seperate list boxes



the code i have got is as follows and now im stuck
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Shopping Cart</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<link rel="StyleSheet" href="css/style.css" type="text/css">

<script language="javascript" type="text/javascript">
dayName = new Array ("Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday")
MonthName = new Array ("January", "February", "March", "April", "May",
"June", "July", "Augest", "September", "October", "November",
"December")
now = new Date</script>

<script language="javascript" type="text/javascript">
function calcTotal(quantity,bill){
if(isNaN(quantity)){
alert('You must enter a number');
}
else {
if(quantity<1 || quantity>5){
alert('Album quantity should be between 1 and 5');
}
else {

var total = "£" + quantity * bill;
document.myForm.totalCost.value=total;
}
}
}
var Album = new Array();
var price= new Array();

function updateTextSelection(x){
addValues(document.myForm.select.options[x].text,document.myForm.select
options[x].value);

}
function updateTextSelection1(x){

addValues(document.myForm.select2.options[x].text,document.myForm.selec
t2.options[x].value);
}
function updateTextSelection2(x){

addValues(document.myForm.select3.options[x].text,document.myForm.selec
t3.options[x].value);
}

function addValues(event,cost){
Album[Album.length] = event
price[price.length] = cost
var i;
var orderString = "";

var bill = 0;

for (i=0;i<price.length;i++){
orderString = orderString + Album[i] + ': \t £' + price[i] + '\n';
bill = bill + parseFloat(price[i]);
}
bill = Math.round(bill * 100)
bill = bill /100;
document.myForm.displayBillDetails.value=orderStri ng;
calcTotal(document.myForm.quantity.value, bill);
}

</script>
</head>
<body>
<form name="myForm" action="">
<table width="939" border="10" bgcolor="#FFFFFF">
<!--DWLayoutTable-->
<tr>
<td width="325" height="55" valign = "top" bgcolor="#000000">
<div align="left" class="style9">
<p align="center"><span class="style style39"><span
class="style8 style40"></span></span> <span class="style style39"><span
class="style8 style40"></span></span>
<script language="javascript" type="text/javascript">
document.write("<h2>Today is " + dayName[now.getDay()] + ", " +
MonthName[now.getMonth()] + ", " + now.getDate() + ", " +
now.getFullYear() + ".<\/h2")</script>
</p>
<p align="center"><span class="style style39"><span
class="style8 style40"></span></span><span class="style style39"><span
class="style8 style40"><span class="style17">
</span></span></span><span class="style style39"><span class="style8
style40"><span class="style17"> </span></span></span></p>
</div></td>
<td width="580" valign="top" bgcolor="#000000"><object
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflas
h.cab#version=6,0,29,0" width="319" height="46">
<param name="BGCOLOR" value="#000000">
<param name="movie" value="flashbuttons/carttxt.swf">
<param name="quality" value="high">
<embed src="flashbuttons/carttxt.swf" width="319" height="46"
quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash" bgcolor="#000000"></embed>
</object></td>
</tr>
<tr>
<td height="76" valign = "top" bgcolor="#000000"><div
align="center"><span class ="style9"><span
class="style15"><em><strong><em><em><strong><em>
<embed src="sound/I Believe In A Thing Called Love.wav"
height=59 width=262></embed>
</em></strong></em></em></strong></em></span> </span></div></td>
<td valign="top" bgcolor="#000000"><h1 align="center"
class="style"2">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflas
h.cab#version=5,0,0,0" width="316" height="57">
<param name="movie" value="flashbuttons/shoppingcarttxt.swf">
<param name="quality" value="high">
<param name="bgcolor" value="#000000">
<embed src="flashbuttons/shoppingcarttxt.swf" quality="high"
pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_P
rod_Version=ShockwaveFlash" type="application/x-shockwave-flash"
width="316" height="57" bgcolor="#000000"></embed>
</object>
</h1></td>
</tr>
<tr>
<td height="888" valign="top" bgcolor="#000000">
<table width="291" border="0">
<tr>
<th width="285" scope="row"><div align="left">
<object
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflas
h.cab#version=5,0,0,0" width="285" height="55">
<param name="movie" value="button1.swf">
<param name="quality" value="high">
<param name="bgcolor" value="#000000">
<embed src="button1.swf" quality="high"
pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_P
rod_Version=ShockwaveFlash" type="application/x-shockwave-flash"
width="285" height="55" bgcolor="#000000"></embed>
</object>
</div></th>
</tr>
<tr>
<th scope="row"><div align="left">
<object
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflas
h.cab#version=5,0,0,0" width="285" height="55">
<param name="movie" value="button2.swf">
<param name="quality" value="high">
<param name="bgcolor" value="#000000">
<embed src="button2.swf" quality="high"
pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_P
rod_Version=ShockwaveFlash" type="application/x-shockwave-flash"
width="285" height="55" bgcolor="#000000"></embed>
</object>
</div></th>
</tr>
<tr>
<th scope="row"><div align="left">
<object
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflas
h.cab#version=5,0,0,0" width="285" height="55">
<param name="movie" value="flashbuttons/button3.swf">
<param name="quality" value="high">
<param name="bgcolor" value="#000000">
<embed src="flashbuttons/button3.swf" quality="high"
pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_P
rod_Version=ShockwaveFlash" type="application/x-shockwave-flash"
width="285" height="55" bgcolor="#000000"></embed>
</object>
</div></th>
</tr>
<tr>
<th scope="row"><div align="left">
<object
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflas
h.cab#version=5,0,0,0" width="285" height="55">
<param name="movie" value="flashbuttons/button4.swf">
<param name="quality" value="high">
<param name="bgcolor" value="#000000">
<embed src="flashbuttons/button4.swf" quality="high"
pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_P
rod_Version=ShockwaveFlash" type="application/x-shockwave-flash"
width="285" height="55" bgcolor="#000000"></embed>
</object>
</div></th>
</tr>
<tr>
<th scope="row"><div align="left">
<object
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflas
h.cab#version=5,0,0,0" width="285" height="55">
<param name="movie" value="flashbuttons/button5.swf">
<param name="quality" value="high">
<param name="bgcolor" value="#000000">
<embed src="flashbuttons/button5.swf" quality="high"
pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_P
rod_Version=ShockwaveFlash" type="application/x-shockwave-flash"
width="285" height="55" bgcolor="#000000"></embed>
</object>
</div></th>
</tr>
<tr>
<th scope="row"><div align="left">
<object
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflas
h.cab#version=5,0,0,0" width="285" height="55">
<param name="movie" value="mainmember.swf">
<param name="quality" value="high">
<param name="bgcolor" value="#000000">
<embed src="mainmember.swf" quality="high"
pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_P
rod_Version=ShockwaveFlash" type="application/x-shockwave-flash"
width="285" height="55" bgcolor="#000000"></embed>
</object>
</div></th>
</tr>
</table>
<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>
<p align="center">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflas
h.cab#version=5,0,0,0" width="230" height="43">
<param name="movie" value="flashbuttons/itemsadded.swf">
<param name="quality" value="high">
<param name="bgcolor" value="#000000">
<embed src="flashbuttons/itemsadded.swf" quality="high"
pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_P
rod_Version=ShockwaveFlash" type="application/x-shockwave-flash"
width="230" height="43" bgcolor="#000000"></embed>
</object>
</p>
<p align="center">
<textarea name="displayBillDetails" cols="50"
rows="10"></textarea>
<span class="style15"><span class="style2 style7
style9"><em><strong><em><em><strong><em>
</em></strong></em></em></strong></em></span></span></p>
<p align="center">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflas
h.cab#version=5,0,0,0" width="89" height="41">
<param name="movie" value="flashbuttons/total.swf">
<param name="quality" value="high">
<param name="bgcolor" value="#000000">
<embed src="flashbuttons/total.swf" quality="high"
pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_P
rod_Version=ShockwaveFlash" type="application/x-shockwave-flash"
width="89" height="41" bgcolor="#000000"></embed>
</object>
</p>
<p align="center">
<input type="text" name="totalCost" value="£">
</p>
<p align="center">&nbsp; </p></td>
<td height="888" align ="center" valign="top" bgcolor="#000000"><div
align="left"></div>
<p>&nbsp;</p> <table width="453" border="0">
<tr>
<th height="171" valign="top"><p>&nbsp;
</p>
<p>&nbsp;</p>
<p>&nbsp;</p> </th>
<th height="171" scope="row" valign="top"><p>
<object
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflas
h.cab#version=6,0,29,0" width="190" height="38">
<param name="BGCOLOR" value="#000000">
<param name="movie" value="flashbuttons/hipcart.swf">
<param name="quality" value="high">
<embed src="flashbuttons/hipcart.swf" width="190"
height="38" quality="high"
pluginspage="http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash" bgcolor="#000000"></embed>
</object>
</p>
<p>&nbsp;</p>
<p>
<select name="select"
onChange="updateTextSelection(this.selectedIndex); ">
<option value=0.00>Please Select Album</option>
<option value=10.99>Makaveli,the don killuminati</option>
<option value=14.99>Bad Boys 10th Anniversary...THE
HITS</option>
<option value=19.99>2pac All Eyes On Me</option>
<option value=12.99>50Cent Get Rich Or Die
Trying</option>
<option value=9.99>Nortorious Big Ready To
Die</option>
<option value=9.99>Eminem Eminem Is Back</option>
<option value=9.99>Snoop Dogg Doggystyle Hits</option>
<option value=8.99>Nas I Am</option>
</select>
</p>
<p>&nbsp; </p> <p
align="center">&nbsp;
</p> <p>&nbsp; </p></th>
<td valign="top"><p>
<object
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflas
h.cab#version=6,0,29,0" width="108" height="38">
<param name="BGCOLOR" value="#000000">
<param name="movie" value="flashbuttons/quantity.swf">
<param name="quality" value="high">
<embed src="flashbuttons/quantity.swf" width="108"
height="38" quality="high"
pluginspage="http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash" bgcolor="#000000"></embed>
</object>
</p>
<p>&nbsp;</p>
<p>
<input type="text" name="quantity" value="1" maxlength=2
onChange=calcTotal(this.value);>
</p> </td>
</tr>
<tr>
<th height="233" valign="top">&nbsp;</th>
<th height="233" scope="row" valign="top"><p>
<object
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflas
h.cab#version=6,0,29,0" width="173" height="36">
<param name="BGCOLOR" value="#000000">
<param name="movie"
value="flashbuttons/chartcarttxt.swf">
<param name="quality" value="high">
<embed src="flashbuttons/chartcarttxt.swf" width="173"
height="36" quality="high"
pluginspage="http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash" bgcolor="#000000"></embed>
</object>
</p>
<p>&nbsp;</p>
<p>
<select name="select2"
onChange="updateTextSelection1(this.selectedIndex) ;">
<option value=0.00>Please Select Album</option>
<option value=9.99>Usher Confessions</option>
<option value=9.99>George Micheal Patience</option>
<option value=9.99>Beyonce Knowles Dangerously In Love</option>
<option value=9.99>Blue Guilty</option>
<option value=9.99>Christina Aguilera Stripped</option>
<option value=9.99>Anastacia Anastacia</option>
<option value=9.99>Avril Lavigne Under My Skin</option>
<option value=9.99>Britney Spears In The Zone</option>
</select>
</p>
<p align="center">&nbsp; </p>
<p align="center">&nbsp;</p>
<p>&nbsp;</p></th>
<td valign="top"><p>&nbsp;
</p>
<p>&nbsp;</p>
<p>&nbsp; </p></td>
</tr>
<tr>
<th width="43" height="313" valign="top"><p>&nbsp;
</p>
<p>&nbsp; </p>
<p>&nbsp;</p>
<p>&nbsp; </p>
<p>&nbsp; </p></th>
<th width="235" height="313" scope="row" valign="top"><p>
<object
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflas
h.cab#version=5,0,0,0" width="173" height="36">
<param name="movie" value="flashbuttons/dnbcart.swf">
<param name="quality" value="high">
<param name="bgcolor" value="#000000">
<embed src="flashbuttons/dnbcart.swf" quality="high"
pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_P
rod_Version=ShockwaveFlash" type="application/x-shockwave-flash"
width="173" height="36" bgcolor="#000000"></embed>
</object>
</p>
<p>&nbsp;</p> <p>
<select name="select3"
onChange="updateTextSelection2(this.selectedIndex) ;">
<option value=0.00>Please Select Album</option>
<option value=12.99>Drum And Bass Arena</option>
<option value=16.99>Andy C</option>
<option value=13.99>Drum And Bass Fiesta</option>
<option value=18.99>Back To The Old Skool Drum And Bass</option>
<option value=14.99>Shot Down On Safari</option>
<option value=14.99>Black Market Presents:Drum And Bass</option>
<option value=11.99>21st Century Drum And Bass</option>
<option value=10.99>Inside The Machine</option>
</select>
</p>
<p align="center">&nbsp;</p>
<p align="center">&nbsp; </p>
<p>&nbsp;</p> <p align="center">&nbsp;
</p>
<span class="style9 style7 style2"><em><span
class="style10"><span class="style2 style7
style9"><em></em></span></span></em></span></div></th>
<td width="160" valign="top"> <div
align="center">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp; </p>
</div>
<span class="style9 style7 style2"><em><span
class="style10"><span class="style2 style7
style9"><em><em><em><em><em></em></em></em></em></em></span></span></em>
</span></td>
</tr>
</table>
<p><em><span class="style10"><span class="style2 style7
style9"><em><em><em> <em><em><em><em>
</em></em></em></em></em></em></em></span></span></em><em><span
class="style10"><span class="style2 style7 style9"><em><em><em>
</em></em></em></span></span></em></p>
</td>
</tr>
<tr>
<td height="31" colspan="2" valign="top" bgcolor="#000000"><div
align="left"><span class="style46"> Last Modified Date:
<script language="JavaScript" type="text/javascript">
<!-- Hide this script from js-challenged browsers --

var months = new Array(13);
months[1] = "January";
months[2] = "February";
months[3] = "March";
months[4] = "April";
months[5] = "May";
months[6] = "June";
months[7] = "July";
months[8] = "August";
months[9] = "September";
months[10] = "October";
months[11] = "November";
months[12] = "December";

var dateObj = new Date(document.lastModified)
var lmonth = months[dateObj.getMonth() + 1]
var fyear = dateObj.getYear()
var date = dateObj.getDate()

document.write(" " + " " + lmonth + " " + date + ", " + fyear)

// Done Hiding -->
</script>
</span></div></td>
</tr>
</table>
</body>

<p>&nbsp;</p>
</form>
</body>
</html>
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #1
1 6049
bin_P19 P wrote:
the code i have got is as follows and now im stuck

<snip>

- you're missing a lot of semicolons.
- there's a lot of content in <th>'s that I think belongs in <td>'s.
- I've been told here that language is no longer used, so:
<script type="text/javascript">
- too many double-quotes in this line:
<h1 align="center" class="style"2">
- the (only) form is closed twice:
</form>
<p>&nbsp;</p>
</form>
- you have 2 arrays containing month names:
MonthName, months
- combine price/item functions:
function updatePricing(objSelect,objSelectIndex) {
var ds=objSelect[objSelectIndex];
addValues(ds.text,ds.value);
}
- consider moving code from updatePricing to addValues
- forgot a ">":
"<h2>Today is " ... ".<\/h2"

There were more changes, I sent a revised version of you page to your
email address.

Mike

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Building Blocks | last post by:
Hi, All I need is a simle calculate form script which contains this: A script that can handle text input, radio buttons, checkboxes, and dropdowns. Each one of these variables will contain a...
53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
3
by: Mike | last post by:
Hey guys I am pulling my hair out on this problem!!!!! Any help or ideas or comments on how to make this work I would be grateful! I have been working on this for the past 4 days and nothing I do...
7
by: rick | last post by:
Can anyone help, I am try to create a simple form using a table, where a user can fill out quanty and price and have a total automatically calculated and inserted in another field. I stuck trying...
5
by: RC | last post by:
I have a form with three text boxes on it. I want the third text box to show the total of the values in the other two text boxes. The first box is named: BoxOne and I type the number 2 into it...
2
by: Davisro | last post by:
I am wondering if it is possible to have a running total of four textboxes so that when any text box is changed I could then calcuate the total of the four boxes and show this on the webform. ...
3
by: ConfusedMay | last post by:
Hi, I need to create a graph report that showed total hours and unattended hours based on certain months and operation code that user input into the form. I have two queries: one to calculate...
4
by: Yonih | last post by:
So I am trying to get this Calculator to work. It needs to take in a vaule, and select a shipping Everythin works great except the shipping part. I need it to take the shipping value and add it to...
8
by: jac130 | last post by:
I need to create a calculator using combo boxes/procedures/functions etc... and some other stuff. most of it works properly, but, i need to create a user defined function that checks if both input...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.