Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7857719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:07:36+00:00 2026-06-02T21:07:36+00:00

I am trying to allow Javascript to calculate a function of several different variables

  • 0

I am trying to allow Javascript to calculate a function of several different variables and results. Honestly I’ve spent the last two days working on it and literally have no idea where to go from here. My code as follows:

<html>
<title>Calculate Your Monthly Payments</title> 
        <script language = "JavaScript"> 
            function Calc(){ 
            var a, res;             
            a = parseFloat(document.monthly.form.value); 
            res1 = a/1000;
            res2 = a/500;
            res3 = a/300;

            if(document.monthly.payments[1].style.visibility = "visible" )
                window.alert("Your monthly repayments have been estimaded to be £" + res1);

            else if(document.monthly.payments[2].style.visibility = "visible" )
                window.alert("Your monthly repayments have been estimaded to be £ " + res2);

            else(document.monthly.payments[3].style.visibility = "visible" )
                window.alert("Your monthly repayments have been estimaded to be £ " + res3);
            } 

        </script> 
</head> 


<div id="container">

        <h2>Calculate Your Monthly Payments</h2> 
        <h4>Please fill in the form below</h4>
         <form name = "monthly"> 
           How much are you borrowing? (£): <br><input name = "form" type = "text" size = 10 id="textarea"> <br><br>

                Mortgage Type: <br>
                <select name = "payments">
                  <option value="" selected>Please Select </option>
                  <option value="1">Mortgage 2.19% fixed until 2015 </option>
                  <option value="2">Mortgage 3.17% fixed until 2017 </option>
                  <option value="3">Mortgage 3.18% fixed until 2024 </option>
                </select>
                <br><br>                

           <input type = "button" value = "Calculate Payments! " onclick = "Calc();"> 
        </form>
</div>
</html>

I have been trying to have the event being displayed as a popup which says

“Your Monthly Payment is …”.

The equation I want to implement should work as whatever you enter is divided by what you choose.

If a is selected then as an example it will be divided by 1000
if b is selected then as an example it will be divided by 500
and if c is selected then as an example it will be divided by 300.

However.. none of this works.

I have been going though the code over and over and have made it work, though only partially as the event then displays two pop-ups. First being option value 1 and second replacing it after being click with option value 2.

The Problem is that:

Upon viewing in a browser and clicking on the “Calculate Payments” button nothing happens. Why is this?


I hope I made this clear since I’m a bit rough with English but I would appreciate any help whatsoever.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T21:07:37+00:00Added an answer on June 2, 2026 at 9:07 pm

    This works – try it.

    <html>
    <title>Calculate Your Monthly Payments</title> 
            <script language = "JavaScript"> 
                function Calc(){ 
                var a, res;             
                a = parseFloat(document.monthly.form.value); 
                res1 = a/1000;
                res2 = a/500;
                res3 = a/300;
    
                if(document.monthly.payments.value == "1" )
                {
                    window.alert("Your monthlys repayments have been estimaded to be £" + res1);
                }
                else if(document.monthly.payments.value == "2" )
                {
                    window.alert("Your monthly repayments have been estimaded to be £ " + res2);
                }
                else if(document.monthly.payments.value == "3" )
                {
                    window.alert("Your monthly repayments have been estimaded to be £ " + res3);
                } 
            }
            </script> 
    </head> 
    
    
    <div id="container">
    
            <h2>Calculate Your Monthly Payments</h2> 
            <h4>Please fill in the form below</h4>
             <form name = "monthly"> 
               How much are you borrowing? (£): <br><input name = "form" type = "text" size = 10 id="textarea"> <br><br>
    
                    Mortgage Type: <br>
                    <select name = "payments">
                      <option value="" selected>Please Select </option>
                      <option value="1">Mortgage 2.19% fixed until 2015 </option>
                      <option value="2">Mortgage 3.17% fixed until 2017 </option>
                      <option value="3">Mortgage 3.18% fixed until 2024 </option>
                    </select>
                    <br><br>                
    
               <input type = "button" value = "Calculate Payments! " onclick = "Calc();"> 
            </form>
    </div>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement a function in javascript that will do the following: Allow
I'm trying to write two batch files that will allow me to switch the
I'm trying to add a menu to my Javascript program that will allow a
Is there a javascript function that will allow me to capture the text that
I am trying to call two javascript functions on single events. Here is my
I'm trying to build a jQuery function that will allow me to produce a
I would like to replace the Javascript confirm() function to allow custom buttons instead
Why does javascript allow me to do the following. a = {two : 'World'};
I am trying to write some javascript to allow me to click on a
Been playing around with JavaScript, and what Im trying to do is only allow

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.