Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Nov 2004
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help with form counting

    Code:
    <html>
    <head>
    <script language=javascript>
    function old()
    {
    x = document.buy.gameboyold.value;
    y = document.buy.amount.value;
    document.buy.amount.value=" ";
    document.buy.amount.value= y+x;
    }
    </head>
    <body>
    <form name=buy>
    <input type=checkbox name=gameboyold onClick="old()">
    <input type=text value=0.00 size=5 name="amount">
    </form>
    </body>
    </html>
    This is supposed to show the dollar amount owed (20)
    but it just writes out: 0.0020 and adds 20 every time it is clicked on help me!!!!!!!!

  • #2
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Well, first of all, gameboyold doesn't have a value. Second of all, amount has a text value, so you need to use parseInt() to retrieve the value as a number.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Edinburgh, UK
    Posts
    402
    Thanks
    2
    Thanked 1 Time in 1 Post
    Okay this is simple to solve, but I'm not sure what you want it to do.

    From the code you supplied the only thing this would do is write 0.00ononononon...... adding on everytime you click the checkbox.

    Is this supposed to write only 20 when the checkbox is checked and then clear the field when the checkbox is cleared?
    Rich

    "An expert is a person who has made all the mistakes that can be made in a very narrow field."

  • #4
    New Coder
    Join Date
    Nov 2004
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    reply

    yes it is

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Edinburgh, UK
    Posts
    402
    Thanks
    2
    Thanked 1 Time in 1 Post
    The following will switch between 20 and 0 if the checkbox is checked and unchecked, respectively.

    Code:
    <html>
    <head>
    <script language="javascript">
    function old(what)
    {
    document.buy.amount.value = what.checked?"20":"0.00";
    }
    </script>
    </head>
    <body>
    <form name=buy>
    <input type=checkbox name="gameboyold" onClick="old(this)" value="20">
    <input type=text value="0.00" size=5 name="amount">
    </form>
    </body>
    </html>
    Hope that helps
    Rich

    "An expert is a person who has made all the mistakes that can be made in a very narrow field."


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •