/    Sign up×
Community /Pin to ProfileBookmark

I’m new to JS and missing something small. Please help

Hi everyone. I am trying to set up a loan approval form. I am looking to have the js file separate from the html. Here is what I have. I think I am not connecting something but am frustrated. Any help would be appreciated.

.htm

<!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

function loanApp(income, credit, education){

if(income >= 0 || 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 >= 3 || totalScore <= 7) {
document.getElementById(output).(“I’m sorry but your loan has been declined.”);
}
else
if (totalScore >= 8 || 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;
}
}

I want to call my function with the document.getElementById.

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @llampton spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...