# Thread: Sample Code Calculation Form Multiplying 4 Numbers

1. Registered User
Join Date
Sep 2011
Posts
2

## 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

2. Registered User
Join Date
Sep 2011
Location
India
Posts
21
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>

<body>
First Input :<input type="text" id="txt1" /><br />
Second Input:<input type="text" id="txt2" /><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>```

3. Registered User
Join Date
Sep 2011
Posts
2
Thanks a lot Mourya. Now I have a starting point to build my form.

There are currently 1 users browsing this thread. (0 members and 1 guests)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•