Results 1 to 3 of 3

Thread: Sample Code Calculation Form Multiplying 4 Numbers

  1. #1
    Join Date
    Sep 2011

    Post 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


  2. #2
    Join Date
    Sep 2011

    Thumbs up

    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.

        <title>Simple Calculator</title>
        <script type="text/javascript">
            var a1=1,a2=2;
            function calculate()
                var choice=document.getElementById('choice');
                var txt1=document.getElementById('txt1').value;
                var txt2=document.getElementById('txt2').value;
                var txtper=document.getElementById('txtper').value;
                var txtresult=document.getElementById('txtresult');
        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>
        <br />
        Result:<input type="text" id="txtresult" /><br />
        <input type="button" value="Calculate" onclick="calculate()" />

  3. #3
    Join Date
    Sep 2011
    Thanks a lot Mourya. Now I have a starting point to build my form.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

Posting Permissions

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

Recent Articles