This will not work. "OBJECT EXPECTED"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 511475
    New Member
    • Nov 2006
    • 9

    #1

    This will not work. "OBJECT EXPECTED"

    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.dt d">
    <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("T he number of cents you entered is equal to $" +
    dollars + ".00");
    else
    window.alert("T he 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="calcCe nts();"
    /></p>
    </form>
    </body>
    </html>
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

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

    Ronald :cool:

    Comment

    • pronerd
      Recognized Expert Contributor
      • Nov 2006
      • 392

      #3
      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.

      Comment

      • AricC
        Recognized Expert Top Contributor
        • Oct 2006
        • 1885

        #4
        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

        Comment

        • pprmrsb
          New Member
          • Nov 2006
          • 1

          #5
          hai 511475

          just change your code from

          var cents = document.money. cents.value;

          to

          var cents = document.forms. money.cents.val ue;
          (or)
          var cents = window.money.ce nts.value;

          Comment

          Working...