# Sample Code Calculation Form Multiplying 4 Numbers

• 09-15-2011, 06:29 AM
feax
Sample Code Calculation Form Multiplying 4 Numbers
Hello everyone I have a long time to program and I would apreciate if you could help me.

I need to write a simple html form.

My form looks like this:

integer variable a11=1
integer variable a12=2

(1) Textbox User Input Integer
(2) Textbox User Input Integer
(3) Textbox fixed non editable value 15%
(4) Dropdown Yes/No

If (4) = Yes then Total = (1)*a11
If (4) = No then Total = (2)*a12

Thanks
• 09-15-2011, 11:29 AM
Mourya
Here is the sample code,

you haven't mentioned what is the use of percentage textbox,

also if you to have just Yes or No as choice , its better to use radio button.

Here we are calling the calculate() function whenever the button is clicked

then access the elements in the page, and do the calculations.

Code:

```<head>     <title>Simple Calculator</title>     <script type="text/javascript">         var a1=1,a2=2;         function calculate()         {             var choice=document.getElementById('choice');             choice=choice.options[choice.selectedIndex].text;                         var txt1=document.getElementById('txt1').value;             var txt2=document.getElementById('txt2').value;             var txtper=document.getElementById('txtper').value;             var txtresult=document.getElementById('txtresult');                         choice=="Yes"?txtresult.value=txt1*a1:txtresult.value=txt2*a2;                                 }     </script> </head> <body>     First Input :<input type="text" id="txt1" /><br />     Second Input:<input type="text" id="txt2" /><br />     Percentage:<input type="text" id="txtper" value="15" readonly="readonly" /><br />     Choice<select id="choice">         <option value="Yes">Yes</option>         <option value="No">No</option>     </select>     <br />     Result:<input type="text" id="txtresult" /><br />     <input type="button" value="Calculate" onclick="calculate()" /> </body> </html>```
• 09-16-2011, 10:14 PM
feax
Thanks a lot Mourya. Now I have a starting point to build my form.

## X vBulletin 4.2.2 Debug Information

• Page Generation 0.10376 seconds
• Memory Usage 2,352KB
• Queries Executed 11 (?)
Template Usage (20):
• (1)bbcode_code_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
• bbcode_parse_complete_precache
• bbcode_parse_complete
• cache_templates
• cache_templates_process
• template_register_var
• template_render_output
• fetch_template_start
• fetch_template_complete
• parse_templates
• notices_check_start
• notices_noticebit
• friendlyurl_resolve_class
• friendlyurl_clean_fragment
• friendlyurl_geturl
• process_templates_complete