By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,069 Members | 1,716 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,069 IT Pros & Developers. It's quick & easy.

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

P: n/a


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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.