ekornmeyer
01-02-2011, 02:47 AM
Hi all,
Decided to start learning JavaScript, started 2 days ago. Anyway, I'm trying to create a simple script spits out a styled result based on a user input.
Here is my JS:
function dispTable (form) {
var userCost2 = form.venCost2.value * 1;
marArray = new Array ("0.05", "0.1", ".15", "0.2", "0.25", "0.3", "0.35", "0.4", "0.45", "0.5", "0.55", "0.6", "0.65", "0.7", "0.75", "0.8");
for (var i=0; i<marArray.length; i++) {
document.tableDiv.innerHTML = "<div>"
document.tableDiv.innerHTML = userCost2;
document.tableDiv.innerHTML = marArray[i];
document.tableDiv.innerHTML = + userCost2 * marArray[i];
document.tableDiv.innerHTML = "<\/div>";
}
}
Here is my HTML:
<div class="container">
<form name="lasoCalcTable">
<span>Enter Vendor Cost</span>
<input class="textForm" name="venCost2" id="venCost2" type="text" size="8" />
<hr />
<input class="butForm" name="calcTblBut" type="button" value="Calculate" onclick="dispTable()" /><br />
</form>
<div title="tableDiv" id="tableDiv">
</div>
</div>
The problem is that nothing is happening when I press the calculation button.
What I would like to happen is to display a div element for each value in the array which displays the entered value from VenCost2, the current Margin %, and the result of VenCost2 * margin%. I want this to display on the same page and underneath the calculation button, preferably not having to reload the page.
I thought this was going to be relatively easy but doesn't seem so!
Thanks for your help
Decided to start learning JavaScript, started 2 days ago. Anyway, I'm trying to create a simple script spits out a styled result based on a user input.
Here is my JS:
function dispTable (form) {
var userCost2 = form.venCost2.value * 1;
marArray = new Array ("0.05", "0.1", ".15", "0.2", "0.25", "0.3", "0.35", "0.4", "0.45", "0.5", "0.55", "0.6", "0.65", "0.7", "0.75", "0.8");
for (var i=0; i<marArray.length; i++) {
document.tableDiv.innerHTML = "<div>"
document.tableDiv.innerHTML = userCost2;
document.tableDiv.innerHTML = marArray[i];
document.tableDiv.innerHTML = + userCost2 * marArray[i];
document.tableDiv.innerHTML = "<\/div>";
}
}
Here is my HTML:
<div class="container">
<form name="lasoCalcTable">
<span>Enter Vendor Cost</span>
<input class="textForm" name="venCost2" id="venCost2" type="text" size="8" />
<hr />
<input class="butForm" name="calcTblBut" type="button" value="Calculate" onclick="dispTable()" /><br />
</form>
<div title="tableDiv" id="tableDiv">
</div>
</div>
The problem is that nothing is happening when I press the calculation button.
What I would like to happen is to display a div element for each value in the array which displays the entered value from VenCost2, the current Margin %, and the result of VenCost2 * margin%. I want this to display on the same page and underneath the calculation button, preferably not having to reload the page.
I thought this was going to be relatively easy but doesn't seem so!
Thanks for your help