Current location: Hot Scripts Forums » General Web Coding » JavaScript » How to add an option for multiple quantities using javascript


How to add an option for multiple quantities using javascript

Reply
  #1 (permalink)  
Old 06-28-05, 09:31 AM
dlogic dlogic is offline
New Member
 
Join Date: Jun 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question How to add an option for multiple quantities using javascript

Is there a way to modify this script so that I can add a quantity option to the selected check boxes. I want the buyer to be able to choose more than one of whatever they check off (preferably via a dropdown) and have the script still give the accurate total at the bottom. Here is the script I am using.

Quote:
<script>
function round(number,X) {
// rounds number to X decimal places, defaults to 2
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function addUp(){
total = 0;
for(x=0; x<document.form1.elements.length; x++){
if(document.form1.elements[x].checked == true){
total += parseFloat(document.form1.elements[x].value);

document.form1.chargetotal.value = round(total,2);
document.form1.total.value = '$' + document.form1.chargetotal.value;
}
}
}
</script>

I'm open to using a completely different script if it will have the same funcionality.

Your Help is MUCH appreciated.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-29-05, 06:29 AM
sarat.pediredla sarat.pediredla is offline
Newbie Coder
 
Join Date: Jun 2005
Location: Newcastle upon Tyne UK
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Why would u not use another field for quantity rather than have the checkbox depict it? Then it is simply a matter of document.form1.chargetotal.value * document.form1.quantity.value;
__________________

--------------------------------
Sarat Pediredla
[Writing a lot about nothing]
Blog : Space & Beyond


<a href="http://www.spreadfirefox.com/?q=affiliates&amp;id=108865&amp;t=68"><img border="0" alt="Get Firefox!" title="Get Firefox!" src="http://sfx-images.mozilla.org/affiliates/Buttons/88x31/take.gif"/></a>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Alter Table Help DDRcasey PHP 0 06-14-05 01:08 AM
How to make read-only form fields Ashantai JavaScript 4 02-15-05 05:26 PM
javascript /forms /checkboxes /arrays ski_woman JavaScript 1 11-16-04 05:08 AM
Order of vbscript and javascript in ASP marlin ASP 0 06-03-04 04:01 PM
Reaaly stuck about javascript over frames muratisik JavaScript 1 12-14-03 12:58 PM


All times are GMT -5. The time now is 10:51 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.