I am a totally new to html and javascript and am attempting to create a simple calculator whose output I subsequently want to graph. To achieve that I seem to need to pass a variable from one script to another, but can not manage to achieve this.
I have managed to compile some code together that I think I can use to expand the calculations to achieve what I need and I have found a helpful chartjs template to create a simple bar chart. However, when I try to override the static input for the chart with my sngTotal variable, for example, the variable does not seem to get recognized in the second script. I attempted to define sngTotal as a global variable, but it either did not work properly or I did not define it properly. Any help would be much appreciated.
<html>
<head>
<title> Savings </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/knockout-3.0.0.js"></script>
<script src="js/globalize.min.js"></script>
<script src="js/dx.chartjs.js"></script>
</head>
<script language="javascript">
function btnCalculateTotal_Click() {
var houses = 0;
var cars = 0;
var sngTotal = 0;
houses = Number(frmSimpleCalculator.txtValue1.value);
cars = Number(frmSimpleCalculator.txtValue2.value);
sngTotal = houses + cars
frmSimpleCalculator.txtTotal.value = sngTotal;
}
</script>
<body bgcolor="#aaaaaa">
<table style="background-color:black; color:white; width:800">
<tr>
<td><strong>calculator</strong></td>
</tr>
</table>
<form name="frmSimpleCalculator" action="" method="get">
<fieldset name="fraSimpleCalculator" style="width:1"><legend>Economic Savings Calculator</legend>
<table width="300" border="0">
<tr> <!-- Value 1 -->
<td align="left">Houses:</td>
<td align="right"><input type="text" value="500" name="txtValue1" size="10" maxlength="5" style="text-align:right"></td>
</tr>
<tr> <!-- Value 2 -->
<td align="left">Cars:</td>
<td align="right"><input type="text" value="25" name="txtValue2" size="10" maxlength="5" style="text-align:right"></td>
</tr>
<tr> <!-- Horizontal rule -->
<td align="center" colspan="2"><hr /></td>
</tr>
<tr> <!-- Total -->
<td align="left">Total:</td>
<td align="right"><input type="text" value="0" name="txtTotal" size="10" maxlength="5" style="text-align:right"></td>
</tr>
<tr> <!-- Calculate Button -->
<td align="center" colspan="2">
<input type="button" value="Calculate Total" name="btnCalculateTotal" style="width:150" OnClick="btnCalculateTotal_Click();">
</td>
</tr>
<script>
$(function () {
var dataSource = [
{ savings: "", Houses: 500, Cars: 300 },
];
$("#chartContainer").dxChart({
dataSource: dataSource,
commonSeriesSettings: {
argumentField: "savings",
type: "bar",
hoverMode: "allArgumentPoints",
selectionMode: "allArgumentPoints",
label: {
visible: true,
format: "fixedPoint",
precision: 0
}
},
series: [
{ valueField: "Houses", name: "Houses" },
{ valueField: "Cars", name: "Cars" }
],
title: "Savings potential",
legend: {
verticalAlignment: "bottom",
horizontalAlignment: "center"
},
pointClick: function (point) {
this.select();
}
});
});
</script>
<div class="title">
<h1>savings</h1>
</div>
<div class="content">
<div class="pane">
<div class="long-title"><h3></h3></div>
<div id="chartContainer" style="width: 250px; height: 440px;" style="position:absolute; TOP:200px; LEFT:350px"></div>
</div>
</div>
</body>
</html>