hi,
hoping i have posted this in the right section this time :)
i am doing my javascript still, and cant figure out why i keep getting an error: object expected message for validateform()
im just not sure what i have done wrong with it, i have tried to give it a function, just cant find where my mistake is. any help would be greatly appreciated, thanks :)
hoping i have posted this in the right section this time :)
i am doing my javascript still, and cant figure out why i keep getting an error: object expected message for validateform()
im just not sure what i have done wrong with it, i have tried to give it a function, just cant find where my mistake is. any help would be greatly appreciated, thanks :)
Code:
<html>
<head>
<title>activity 2.22</title>
</head>
<script type="text/javascript">
function validateform()
{
var element;
var BikeMoney;
var TVMoney;
var iPodMoney;
var CarPrice;
var flag="OK";
element=document.getElementsByTagName('input');
for (counter=0; counter<element.length; counter++)
{
switch (element[counter].type)
{
case "submit":
break;
default:
if(isNaN(element[counter].value))
{
alert("You need to enter a number into " + element[counter].name);
var flag="NotOK";
}
else
{
BikeMoney=element[0].value;
TVMoney=element[1].value;
iPodMoney=element[2].value;
CarPrice=element[3].value;
}
}
}
}
if (var flag=="OK")
{
TotalMoney = parseFloat(BikeMoney) + parseFloat(TVMoney) + parseFloat(iPodMoney);
if (TotalMoney >= CarPrice)
{
alert("The total money is " + TotalMoney + " and the car price is " + CarPrice + " and you can afford the car");
}
else
{
alert("The total money is " + TotalMoney + " and the car price is " + CarPrice + " and you cannot afford the car");
}
}
</script>
<body>
<form name="inputform" method="post" action="">
<table>
<tr><td>Enter money from bike sale</td><td><input type="text" name="Bike Money"></td></tr>
<tr><td>Enter money from TV sale</td><td><input type="text" name="TV Money"></td><tr>
<tr><td>Enter money from iPod sale</td><td><input type="text" name="iPod Money"></td><tr>
<tr><td>Enter the price of the car</td><td><input type="text" name="Car Price"></td></tr>
<tr><td></td><td><input type="submit" value="Submit Details" onclick=validateform();
</table>
</form>
</body>
</html>
Comment