I have been working on this homework project a couple of days now and am stumped. I am trying to perform some basic calculations using JS but for some reason it is just completely ingoring my functions and won't do anything when I press my calculate button. When I press the clear button I tried setting breakpoints and they are just skipped over, the form is not done yet, but I am trying to at least test the first portion that requires square footage be calculated to make sure I am on the right path. Couple things I have noticed, it does not like my submit buttons, something wrong with them? my onclick event? When I coded the buttons as button and not input, the function name in the onclick event turned blue instead of black, I am assuming there is a reason for this, since the function names I have not written yet for objects of the form are black. Of course using button instead of input won't work because they looked funky in the browsers. Any feedback is much appreciated as always!
function getSquareFoot()
{
var InputWidth=parseInt(document.getElementById('inputWidth').value);
var InputDepth=parseInt(document.getElementById('inputDepth').value);
var SquareFoot = document.getElementById('SquareFoot');
var msg=[];
if (isNaN('inputWidth'))
{ msg.push('Please enter a number');}
if (isNaN('inputDepth'))
{msg.push('Please enter a number');}
if (msg.length > 0) {
SquareFoot.innerHTML = msg.join(', ');
}
else { SquareFoot.innerHTML = InputWidth * InputDepth / 12;
}
}
function getpriceSqft()
{
var priceSqft=parseFloat(document.getElementById('priceSqft').value);
var BasePrice=document.getElementById('BasePrice');
var msg=[];
if (isNaN('priceSqft'))
{ msg.push('Please enter a number');}
if (msg.length > 0) {
BasePrice.innerHTML = msg.join(', ');
}
else {BasePrice.innerHTML = priceSqft * getSquareFoot()}
}
function calculateTotal()
{
{
var Total = getpriceSqft()
document.getElementById('Total')
}
}
function Clear()
{
document.DeskCalculator.InputWidth.value = '';
document.DeskCalculator.InputDepth.value = '';
document.DeskCalculator.SquareFoot.value = '';
document.DeskCalculator.BasePrice.value = '';
document.DeskCalculator.priceSqft.value = '';
document.DeskCalculator.Total.value = '';
}
<div id="divOutside">
<form name="DeskCalculator" id="DeskCalculator" onsubmit="calculateTotal()" action="test">
<fieldset id="fieldset1">
<legend>Desk Calculator</legend>
<fieldset id="fieldset4">
<legend>Size</legend>
<p>Width (inches):       Depth (inches):<br/>
<input type="text" id="inputWidth" onchange="getSquareFoot()" />    <input type="text" id="inputDepth" onchange="getSquareFoot()"/><br/>
Square Feet:                             Price Per Sq.Ft.:                   Base Price:<br/>
<input type="text" id="SquareFoot" onchange="getSquareFoot()" value ="" />    = <input type="text" id="priceSqft" onchange="getpriceSqft()" />    <input type="text" id="BasePrice" onchange="getpriceSqft()" value="" />
</p> </fieldset>
<fieldset id="fieldset3">
<legend>Drawers</legend>
<input type="radio" name="SelectedDrawer" value="one" onclick="getDrawers()" />One($35) <input type="radio" name="SelectedDrawer" value="two"onclick="getDrawers()" />Two ($60)
<input type="radio" name="SelectedDrawer" value="custom"onclick="getDrawers()" />Custom <select id="custom" name="SelectedDrawer" onchange="getDrawers()">
<option value="three">3</option>
<option value="four">4</option>
<option value="five">5</option>
</select>
</fieldset>
<fieldset id="fieldset2">
<legend>Wood</legend><p>
<br/>
<input type="radio" name="SelectedWood" value="Veneer" onclick="getWood()" />Veneer             <input type="radio" name="SelectedWood" value="Oak" onclick="getWood()" />Oak (+ $50)<br/>
<br/>
<input type="radio" name="SelectedWood" value="Maple" onclick="getWood()" />Maple (+ $75) <input type="radio" name="SelectedWood" value="Cherry" onclick="getWood()" />Cherry (+ $100)<br/>
</p>
</fieldset>
<p> Total Cost:<input type="text" id="Total" value=" " /> <br/> <br />
<input type="submit" onclick= "calculateTotal()" id="Calculate" value="Calculate Price" /><input type="submit" value="Clear" onclick= "Clear()" />
</p>
</fieldset>
</form>
</div>
</body>
</html>

New Topic/Question
Reply


MultiQuote





|