1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Newbie Needs Help!

Discussion in 'Web Design & Development' started by missmomo, Jan 5, 2013.

Thread Status:
Not open for further replies.
Advertisement
  1. missmomo

    missmomo Thread Starter

    Joined:
    Jan 5, 2013
    Messages:
    1
    Hi All

    I have to create a an interactive calculator for my uni assignment and have been coming up with a few problems!
    I can't seem to get my calculator to work, I have followed all the links given to me and have also used on-line sites but have drawn a blank so far! :confused:

    I've created the below code, its for a loan calculation form, it is pretty basic I think but I just need it to give me a total back which it currently isn't doing.

    I'm currently using Dreamweaver CS6 and have been opening it up in IE9 and Google Chrome.

    All help is appreciated and I'll try answer any questions to the best of my knowledge. Thanks :)




    <form>
    <form action="" id="LoanCalculator">
    <form action="" id="LoanCalculator" onsubmit="return false;">


    <legend>Calculate Your Loan Today!</legend><br />
    <fieldset>

    <legend>About You!</legend><br />

    <label >Name:</label>
    <input type="text" id="Name"
    name="Name" value="Enter Name" /><br /><br />

    <label >Age:</label> <br />
    <input type="radio" name="Age" value="Age1" onclick="calculateTotal()" /> Under 21 <br />
    <input type="radio" name="Age" value="Age2" onclick="calculateTotal()" /> 22 - 30 <br />
    <input type="radio" name="Age" value="Age3" onclick="calculateTotal()" /> 31 - 40 <br />
    <input type="radio" name="Age" value="Age4" onclick="calculateTotal()" /> 40+ <br /> <br />


    <label >Weekly Salary:</label>
    <select id="WSalary">
    <option value="None">Select Salary</option>
    <option value="0">Less Than £500</option>
    <option value="500">£501 - £1,000</option>
    <option value="1000">£1,001 - £1,500</option>
    <option value="1500">£1,501 - £2,000</option>
    <option value="2000">£2,000 +</option>
    </select><br /><br />

    </fieldset>



    <fieldset>
    <legend >About The Loan!</legend> <br />


    <label >Please Enter The Loan Amount:</label>
    <input type="Number" id="LoanAmount"
    name="LoanAmount" value="Enter Loan Amount" /><br /><br />


    <label >Repayment Period:</label><br />

    <input type="radio" name="RepaymentDate" value="Period1" onclick="calculateTotal()" /> 0 - 10 Days <br />
    <input type="radio" name="RepaymentDate" value="Period2" onclick="calculateTotal()" /> 11 - 15 Days <br />
    <input type="radio" name="RepaymentDate" value="Period3" onclick="calculateTotal()" /> 16 - 20 Days <br />
    <input type="radio" name="RepaymentDate" value="Period4" onclick="calculateTotal()" /> 21 - 25 Days <br />
    <input type="radio" name="RepaymentDate" value="Period5" onclick="calculateTotal()" /> 26 - 31 Days <br /><br />


    <label >Payment Protection Insurance (PPI)</label>
    <input type="checkbox" id="AddPPI" /> <br /> <br />


    <div id="LoanTotal"></div>
    </fieldset> </form>


    <script language="javascript">


    function getLoanAmount(){
    var theForm = document.forms["LoanCalculator"];
    var LoanAmount = theForm.elements["LoanAmount"];
    var Amount =0;
    if(LoanAmount.value!="")
    {Amount = parseInt(LoanAmount.value); }
    return Amount;}



    var Loan_Cost = new Array();
    Loan_Cost["Period1"]=25;
    Loan_Cost["Period2"]=50;
    Loan_Cost["Period3"]=75;
    Loan_Cost["Period4"]=120;
    Loan_Cost["Period5"]=150;

    function getLoanCost ()
    {var LoanCost=0;
    var theForm = document.forms["LoanCalculator"];
    var selectedLoanCost = theForm.elements["RepaymentDate"];
    RepaymentDate.length = 5
    for(var i = 0; i < RepaymentDate.length; i++)
    {if(RepaymentDate.checked)
    {LoanCost = Loan_Cost[selectedRepaymentDate.value]; break} }
    return LoanCost;}


    function PPI()
    { var PPI=0 ;
    var theForm = document.forms["LoanCalculator"];
    var PPI = theForm.elements["AddPPI"];
    if(AddPPI.checked==true)
    { PPI=25; }
    return PPI;}


    var WeeklySalary= new Array();
    Salary["None"]=0;
    Salary["0"]=25;
    Salary["500"]=50;
    Salary["1000"]=75;
    Salary["1500"]=100;
    Salary["2000"]=125;


    function getSalaryTotal()
    {var WeekSalary=0;
    var theForm = document.forms["LoanCalculator"];
    var SelectedSalary = theForm.elements["WSalary"];
    WeekSalary = Salary[selectedWSalary.value];
    return WeekSalary; }



    var AgeGroup = new Array();
    Age["Age1"]=10;
    Age["Age2"]=15;
    Age["Age3"]=20;
    Age["Age4"]=25;


    function getAgeFee ()
    {var AgeFee=0;
    var theForm = document.forms["LoanCalculator"];
    var selectedAge = theForm.elements["Age"];
    selectedAge.length = 4
    for(var i = 0; i < selectedAge; i++)
    {if(Age.checked)
    {AgeFee = Age[Age.value]; break; } }
    return AgeFee;}



    function getTotal()
    { var Total = getLoanAmount() + getLoanCost () + PPI() + getSalaryTotal() + getAgeFee ();
    var divobj = document.getElementById('LoanTotal');
    divobj.style.display='block';
    divobj.innerHTML =
    Name+" the total Cost of Loan is £"+Total;}

    function hideTotal()
    {var divobj = document.getElementById('LoanTotal');
    divobj.style.display='none';}


    </script>
     
  2. JiminSA

    JiminSA

    Joined:
    Dec 15, 2011
    Messages:
    3,327
    First Name:
    Jim
    I see you are using onclick to kick-off a javascript function - calculateTotal(), which is not in your code. Maybe this link will also give you an idea of how it should all hang together - I hope so:)
     
  3. DexterDave

    DexterDave

    Joined:
    May 10, 2011
    Messages:
    310
    try posting your code and problem on Stackoverflow.com - Guys there are very helpful, and you might get a better answer there
     
  4. JiminSA

    JiminSA

    Joined:
    Dec 15, 2011
    Messages:
    3,327
    First Name:
    Jim
    I'm assuming that the help I gave earlier is not enough as, DexterDave also apparently assumes. That being the case, you mustn't be afraid to point it out:) and ask for a better response (check my motto)...
    You need to consolidate those wonderful little javascript functions by building another - presumably, calculateTotals - which will take what has been entered by the client/user and do your calculations.
    Now, I am no javascript expert, but I do know that it functions client side, so I assume again that all your calculations can be done if all the information is available, which is what you want to achieve.
    However if it were my project I would be inclined to submit the form and utilise php to validate all the input and then use the information gathered to output the calculations.
    What we need to know from you now is how are you going to approach this project? Javascript only (you lose me there) or by submitting the form and using php?
     
  5. DexterDave

    DexterDave

    Joined:
    May 10, 2011
    Messages:
    310
    @ JiminSA: Nope, wasn't shooting down your answer, but I just think that this is the wrong forum for such a programming specific question. Stackoverflow deals with problems like these, and changes are very good that he will get multiple responses, since up to now, he has actually only had one response (disregarding mine, since it isn't actually an answer to the direct question).
     
  6. JiminSA

    JiminSA

    Joined:
    Dec 15, 2011
    Messages:
    3,327
    First Name:
    Jim
    I agree with you Dave - stackoverflow is very helpful in terms of supplying the coded solution, but the policies here tend towards pointing the enquirer towards the solution without actually coding it for them. Which I believe is a better way to cultivate a healthier learning curve:)
     
  7. DexterDave

    DexterDave

    Joined:
    May 10, 2011
    Messages:
    310
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1083896

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice