www.webdeveloper.com
Results 1 to 4 of 4

Thread: Price/Quantity Calculator Code Help!!!!!!!!

  1. #1
    Join Date
    Nov 2012
    Posts
    4

    Exclamation Price/Quantity Calculator Code Help!!!!!!!!

    Here is my code, i just can't get my 'Total and Clear' buttons to work, can someone help?!

    <!DOCTYPE HTML>
    <html>

    <head>
    <body bgcolor="#B45F04">

    <title>Welcome to my Dead Frontier Shop!</title>
    </head>

    <body>

    <h1><center>I Have the Best Prices On Dead Frontier In game Items!</Center></h1>



    <br>

    <center><img src="deadfrontier.jpg" alt="dead frontier"></center>




    <br>


    <form name="myForm">




    Please Choose What In game itmes you need:
    <select name="Items">
    <option value="10">Vulcan $10</option>
    <option value="5">AA-12 $5</option>
    <option value="3">Corpse Shooter $3</option>
    <option value="2">Titanium Blades $2</option>
    </select>

    Please Choose the color you want:
    <select name="Items">
    <option value="1">Red</option>
    <option value="2">Black</option>
    <option value="3">Blue</option>
    <option value="4">Purple</option>
    </select>
    Please Choose When do you need it by:
    <select name="time">
    <option value="1">Right Away</option>
    <option value="2">Within 24 hours</option>
    <option value="3">Within the week</option>
    <option value="4">On the Weekened</option>
    </select>
    Please Choose The Amount You want:
    <select name="quantity">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    </select>

    <input type="button" value="Total Price" onclick=' var Totalprice = 0;
    Totalprice = document.myForm.Items.value * document.myForm.quantity.value;
    document.myForm.total.value = totalprice
    '>
    <td>
    <input type="button" value="Clear" onclick=
    'document.forms[0].price.value ="0.00"
    '/>
    </td>

    <br><br>
    <center><input type="text" name="total"></center>

    </form>
    </body>
    </html>

  2. #2
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    227
    The console reveals two errors:

    Code:
    document.myForm.total.value = totalprice
    should be
    Code:
    document.myForm.total.value = Totalprice
    The other problem is this:
    Code:
    document.forms[0].price.value = "0.00"
    There is no input named "price" in the form.

  3. #3
    Join Date
    Nov 2012
    Posts
    4
    Quote Originally Posted by refreezed View Post
    The console reveals two errors:

    Code:
    document.myForm.total.value = totalprice
    should be
    Code:
    document.myForm.total.value = Totalprice
    The other problem is this:
    Code:
    document.forms[0].price.value = "0.00"
    There is no input named "price" in the form.
    I changed the way you described, but when I click on total i get NaN. And I still can't get the clear button to work, please help with the coding for these two parts!

  4. #4
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    227
    You have two select elements named Items, so (at least in Google Chrome) document.myForm.Items is an array with two elements. I guess you should rename the color selector to "colors" or something.

    And have you added a new form element named "price"? Or maybe you actually meant to point at the input element named "total"?

    Code:
    document.myForm.total.value = "0.00"
    If you want to reset all form elements you can just replace your "Clear" button with the following:
    Code:
    <input type="reset" value="Clear" />
    Edit: also, I noticed now that you have two <body> tags in your html code - there should only be one.
    Last edited by ReFreezed; 11-11-2012 at 09:21 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles