# Calculating Price from Quantity selected by the user

• 08-26-2013, 01:09 AM
spazzo246
Calculating Price from Quantity selected by the user
ok so i have this form on my web page.

HTML Code:

```<div id="purhcaseForm">         <form id="purchase">                 <br> Item Price: \$463.50                 <br> Please Select Quantity                 <input type='button' name='subtract' onclick='javascript: document.getElementById("qty").value--;' value='-'/>                 <input type='button' name='add' onclick='javascript: document.getElementById("qty").value++;' value='+'/>                 <input type='text' name='qty' id='qty' />```
what i want to do is in the simplest way possible is to have another box which outputs the total order price taking into account the quantity the user has specified. im very new to java script and do not have any clue as to where to start ( i dont even know if what i have is the best way of achieving my objective) all help is apreciated :)
• 08-26-2013, 04:45 AM
vwphillips
Code:

```<!DOCTYPE html> <html lang="en"> <head>   <meta charset="utf-8" />   <script> function Total(qty,ud,total,value){  qty=document.getElementById(qty);  ud>0?qty.value++:qty.value--;  qty.value=Math.max(qty.value,0);  document.getElementById(total).value=qty.value*value; }   </script> </head> <body>     <div class="slider-vertical"></div> <div id="purhcaseForm">         <form id="purchase">                 <br> Item Price: \$463.50                 <br> Please Select Quantity                 <input type='button' name='subtract' onclick='Total("qty",-1,"total",463.50);' value='-'/>                 <input type='button' name='add' onclick='Total("qty",1,"total",463.50);' value='+'/>                 <input type='text' name='qty' id='qty' readonly=true value="0"/>                 <input type='text' name='total' id='total' value="0" />       </form> </div>         </body> </html>```
• 08-27-2013, 07:01 AM
spazzo246
Re: Calculating Price from Quantity selected by the user
Hi, thats exactly what i wanted. if its to much trouble dw about it but can you briefly explain what this part of the code does?

HTML Code:

```<script> function Total(qty,ud,total,value){  qty=document.getElementById(qty);  ud>0?qty.value++:qty.value--;  qty.value=Math.max(qty.value,0);  document.getElementById(total).value=qty.value*value; }   </script>```

I want to get some sort of basic understanding as to what you did. Thanks apreciate all your help
• 08-27-2013, 11:43 AM
Vic, i can't believe my eyes you're using inline onclicks

## X vBulletin 4.2.2 Debug Information

• Page Generation 0.07423 seconds
• Memory Usage 2,357KB
• Queries Executed 11 (?)
Template Usage (21):
• (1)bbcode_code_printable
• (2)bbcode_html_printable
• (1)footer
• (1)gobutton
• (1)navbar_moderation
• (1)navbar_noticebit
• (2)option
• (1)spacer_close
• (1)spacer_open

Phrase Groups Available (3):
• global
• postbit
Included Files (19):
• ./global.php
• ./includes/class_bootstrap.php
• ./includes/init.php
• ./includes/class_core.php
• ./includes/config.php
• ./includes/functions.php
• ./includes/class_friendly_url.php
• ./includes/class_hook.php
• ./includes/class_bootstrap_framework.php
• ./vb/vb.php
• ./vb/phrase.php
• ./includes/functions_calendar.php
• ./includes/class_bbcode_alt.php
• ./includes/class_bbcode.php
• ./includes/functions_bigthree.php
• ./includes/functions_notice.php

Hooks Called (41):
• init_startup
• init_startup_session_setup_start
• database_pre_fetch_array
• database_post_fetch_array
• init_startup_session_setup_complete
• global_bootstrap_init_start
• global_bootstrap_init_complete
• cache_permissions
• fetch_foruminfo
• global_state_check
• global_bootstrap_complete
• global_start
• style_fetch
• global_setup_complete
• bbcode_fetch_tags
• bbcode_create
• bbcode_parse_start
• cache_templates
• cache_templates_process
• template_register_var
• template_render_output
• fetch_template_start
• fetch_template_complete
• parse_templates