Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    new to JS and Im looking for some help [CODE] ?

    I am working on a basic function to determine eiligibility for a loan. I am looking to have the html and js as separate files. I am missing something or not connecting the dots correctly. Any help would be appreciated.

    .htm

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    		<script type="text/javascript" src="new_file.js"></script>
            <title>New Web Project</title>
    		<style type="text/css">body {background-color: #CCCCCC}</style>
    		
        </head>
        <body>
            <h1>Loan Application</h1>
    		
    <form id="Loan Application" action="form_action.asp">
    <fieldset>
    <legend>Please enter the following information:</legend>
    <label for="Annual Income">Annual Income</label>
    <br />
    <input type="text" name="annual income" id="annual income" value="40000" />
    <br />
    <label for="credit">Credit Score</label>
    <br />
    <input type="text" name="credit" id="credit" value="500" />
    <br />
    <label for="education">Education Level</label>
    <br />
    <select name="education" id="education">
    <option value="High School">High School</option>
    <option value="Associate's Degree">Associate's Degree</option>
    <option value="Bachelor's Degree">Bachelor's Degree</option>
    <option value="Postgraduate Degree">Postgraduate Degree</option>
    </select>
    <br />
    <br />
    <input type="button" value="Calculate" onclick="result()" />
    <br />
    </fieldset>
    <DIV id="output"> </DIV>
    </form>	
    		
        </body>
    </html>

    .js

    PHP Code:
    function loanApp(incomecrediteducation){
        
        if(
    income >= || income <= 40000){
            return 
    1;
        } else {
            if(
    income >=40001 || income <= 80000){
                return 
    3;
                } else {
                        return 
    5;
                        }}
        if(
    credit >= 300 || credit <= 500){
            return 
    1;
            }else if(
    credit >= 501 || credit <=650){
                return 
    3;
                }else {
                    return 
    5;
                    }}
                    
        switch (
    education) {
            case 
    "High School":
                
    result 1;
                break;
            case 
    "Associate's Degree":
                
    result 2;
                break;
            case 
    "Bachelor’s Degree":
                
    result 3;
                break;
            case 
    "Postgraduate Degree":
                
    result 5;
            default:
                
    result "That was not a valid selection.";
        }
        
    function 
    result(answer){
        var 
    answer income credit education;
        if (
    totalScore >= || totalScore <= 7) {
            
    document.getElementById(output).("I'm sorry but your loan has been declined.");
        }
        else 
            if (
    totalScore >= || totalScore <= 10) {
                
    document.getElementById(output).("The loan is approved at 8.5% interest rate.");
            }
            else {
                
    document.getElementById(output).("Your approved at a 7% interest rate.");
                return 
    answer;
            }

    Last edited by VIPStephan; 02-20-2012 at 09:19 AM. Reason: wrapped appropriate BB tags around code

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    This construct is illegal
    Code:
    document.getElementById(output).("I'm sorry but your loan has been declined.");
    As you are trying to update the content (HTML) of a DIV, you'll have to use something like this
    Code:
    document.getElementById("output").innerHTML = "I'm sorry but your loan has been declined.";

  • Users who have thanked devnull69 for this post:

    llampton (02-20-2012)

  • #3
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    just confused

    Im new to JS and trying to learn. I'm just confused as to where I am going wrong. I am trying to use the document.getElementById to call my function I think. Im starting to get confused. I'm pretty sure my js is good. trying to build it into a table

  • #4
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    inner

    I'm missing the inner tag

  • #5
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    If my correction doesn't help you, please try to explain most exactly what you WANT to do (less technical more semantical).

    By the way, there is one more inconsistency that I didn't notice at first. Your "switch" command is not inside one of the functions, yet you are using a variable "education" that is only available inside the function loanApp(). You are also using "education" inside the result() function where it is also undefined

    Even more, your conditions seems to be off
    Code:
    if(income >= 0 || income <= 40000){
    you are using the OR operator and I think it should be AND
    Code:
    if(income >= 0 && income <= 40000){
    Additionally, you are using a variable "result" in your switch command which is also the name of a function in the same scope.
    Last edited by devnull69; 02-20-2012 at 09:18 AM.

  • Users who have thanked devnull69 for this post:

    llampton (02-20-2012)


  •  

    Posting Permissions

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