Connecting Tech Pros Worldwide Help | Site Map

This will not work. "OBJECT EXPECTED"

Newbie
 
Join Date: Nov 2006
Posts: 9
#1: Nov 14 '06
Originally Posted by 511475
this program is supposed to give the user the ability to enter numbers
in cents and tell you how many dollars you have. Please anybody can
tell me what's wrong. been working on it two weeks

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Cents to Dollars</title>
<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
function calcCents (){
var cents = document.money.cents.value;
var dollars = 0;
var dollars = cents / 100;
var change = cents % 100;
if (change != 00)
window.alert("The number of cents you entered is equal to $" +
dollars + ".00");
else
window.alert("The number of cents you entered is equal to $" +
dollars);

}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
</head>
<body>
<form name="money" action="">
<p>Cents: <input type="text" name="cents" /><br />
<input type="button" value="Cents to Dollars" onclick="calcCents();"
/></p>
</form>
</body>
</html>
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#2: Nov 14 '06

re: This will not work. "OBJECT EXPECTED"


Don't know that much about it, but don't you need an id='cents' tag in your input statement?

Ronald :cool:
Expert
 
Join Date: Nov 2006
Posts: 392
#3: Nov 15 '06

re: This will not work. "OBJECT EXPECTED"


Quote:

Originally Posted by ronverdonk

Don't know that much about it, but don't you need an id='cents' tag in your input statement?

Ronald :cool:

ronverdonk has it. The code is looking for a tag with an ID of "cents", but there are not any. So the object that it should be getting is null.
Expert
 
Join Date: Oct 2006
Location: NC
Posts: 1,722
#4: Nov 15 '06

re: This will not work. "OBJECT EXPECTED"


The code you posted seems to be working somewhat fine for me. You may want to get rid of the extra .00 after say you put in 150 it will give you 1.5.00
Newbie
 
Join Date: Nov 2006
Posts: 1
#5: Nov 17 '06

re: This will not work. "OBJECT EXPECTED"


hai 511475

just change your code from

var cents = document.money.cents.value;

to

var cents = document.forms.money.cents.value;
(or)
var cents = window.money.cents.value;
Reply