Linking To Form.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tterb
    New Member
    • Apr 2008
    • 1

    Linking To Form.

    Hi there, Im a little stuck here, my problem is im making a house insurance form where you enter data into the feilds and the calculations link back to create the end result amount i cant seem to get the right values in the form i have all the variables correct but just linking the two is where i need a little help where have i gone wrong? and what do i need to change in order to make it work.

    Here is my code so far:

    Code:
    <script language="javascript" type="text/javascript">
    function houseInsurance( ){
    var basePay = (a*0.0015)+(b*0.012)
    var x = (basePay*1.15)
    var y = (basePay*1.05)
    var  totalPremiums = (x+y)*1.10
    var result = c*totalPremiums
    return result;
    }
    function calculate( ) {
    var a = parseInt (document.form.housevalue.value)
    var b = parseInt (document.form.contentsvalue.value)
    var c = parseInt (document.form.noclaimbonus.value)
    document.form.total.value = result
    }
    </script>
    
    <body>
    <form name = "houseInsurance"><h1>House Inurance:</h1>
    House Value<br>
    <input type = "Text" value = "Enter Amount" name = "1">
    <br>
    Contents Value<br>
    <input type = "Text" value = "Enter Amount" name = "2">
    <br>
    No Claim Bonus<br>
    <input type = "Text" value = "Enter Amount" name = "3">
    <br>
    <input type = "button" value = "result" Name = "click"
    onClick = "calculate()">
    <br>
    Total<br>
    <input type = "Text" value = "Total" name = "4">
    </body>
    I hope you guys are so kind enough to help me out with this one

    Cheers
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

    #2
    Originally posted by tterb
    i cant seem to get the right values in the form
    What specificly is not right? Getting the wrong number, not getting a number at all, getting an error message?



    Originally posted by tterb
    just linking the two is where i need a little help
    Linking what two to what?


    Originally posted by tterb
    Here is my code so far:

    Code:
    <script language="javascript" type="text/javascript">
    function houseInsurance( ){
    var basePay = (a*0.0015)+(b*0.012)
    var x = (basePay*1.15)
    var y = (basePay*1.05)
    var  totalPremiums = (x+y)*1.10
    var result = c*totalPremiums
    return result;
    }
    function calculate( ) {
    var a = parseInt (document.form.housevalue.value)
    var b = parseInt (document.form.contentsvalue.value)
    var c = parseInt (document.form.noclaimbonus.value)
    document.form.total.value = result
    }
    </script>
    
    <body>
    <form name = "houseInsurance"><h1>House Inurance:</h1>
    House Value<br>
    <input type = "Text" value = "Enter Amount" name = "1">
    <br>
    Contents Value<br>
    <input type = "Text" value = "Enter Amount" name = "2">
    <br>
    No Claim Bonus<br>
    <input type = "Text" value = "Enter Amount" name = "3">
    <br>
    <input type = "button" value = "result" Name = "click"
    onClick = "calculate()">
    <br>
    Total<br>
    <input type = "Text" value = "Total" name = "4">
    </body>

    I am assuming there must be some missing code here.

    1. Almost none of the JavaScript lines are terminated with semi-colons.

    2. I do not see where the houseInsurance( ) function is ever acutally called. Is there code that was left out.

    3. The houseInsurance( ) function is accessing variables named a,b,x, and y that do not seem to be declared anywhere.

    4. The calculate( ) function accesses a variable named result that does not seem to be declared.

    5. The calculate( ) function seems to be trying to access input fields with IDs housevalue, contentsvalue, and noclaimbonus. There are no fields in the HTML with those IDs.

    Comment

    Working...