Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Thanked 0 Times in 0 Posts

    Help with a Purchase Order Form

    Hello, I'm new to this forum and new to JS as well. I am trying to make a purchase order form for a zoo I'm creating. Basically I need it to add the total of the items I select and then send the order. However, I get various errors which I will post in screenshots. The first is when I ran the JS through a JS lint, then the second one is showing an error on line 111 of my code. Also, each one of the drop down values comes up as "undefined" an it doesn't calculate the total. Again, I'm very new to JavaScript so I'm not really sure how to go about fixing this problem so I can get this working. Any advice or help would be great! I'll post the screenshots as well.
    Attached Thumbnails Attached Thumbnails -error-jpg   -js-jpg  

  2. #2
    New to the CF scene
    Join Date
    Apr 2013
    Thanked 0 Times in 0 Posts
    Also here is the actual file with the code I am working with.
    Attached Files Attached Files

  3. #3
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Thanked 1,013 Times in 1,010 Posts
    I am trying to make a purchase order form for a zoo I'm creating.
    Lshipmp.. This is homework. But here's a hint for you to try:

    You need to have an onchange attribute in your select dropdowns that calls a js function.
    You need to pass that func. the toy name preface ie; "Tiger" and the dropdown value.
    The fuc. can find the item cost and multiply the values together and then place the answer in the subtotal slot.
    You can also add the subtotals of all four items together here and place it in the Total box. You would have to set the subs equal to zero as globals first.
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.

  4. #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,703 Times in 2,679 Posts
    You want something like this for each article:
    Elephant T-Shirts $12 each 
    <select id="Elephant" name="Elephant" size="1" onchange = "getValue(this)">
    <option value=10>10</option>
    <option value=9>9</option>
    <option value=8>8</option>
    <option value=7>7</option>
    <option value=6>6</option>
    <option value=5>5</option>
    <option value=4>4</option>
    <option value=3>3</option>
    <option value=2>2</option>
    <option value=1>1</option>
    <option value=0 selected>0</option>
    Sub-totals: Elephant Shirts $<input type = "text" size = 3 id = "Elephantcost" value = 0 readonly">
    <script type = "text/javascript">
    function getValue(which) {
    var d = which.id;
    if (d == "Elephant") { var itemcost = 12}  // assign itemcost for other articles according to value of d
    if (d == "Penguin") { var itemcost = 14}
    var val = which.value;  // how many?
    var amt = val * itemcost;
    if (val != 0) {
    alert ("You have ordered " + val + " " + d + " T-Shirts at $12 each which comes to $" + amt);
    var box = d +"cost";
    document.getElementById(box).value = amt;
    Note that your option values are numbers, not strings. If you place them in quotes they become string values.

    Please do not post thumbnails - they are useless.

    In the beginner's mind there are many possibilities, but in the expert's mind there are few” - Shunryu Suzuki (Japanese Zen priest, ?-1971)
    Last edited by Philip M; 04-21-2013 at 06:31 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


Posting Permissions

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