SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Apr 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form Calculation

    Hi, I'm new to Javascript and am having major problems trying to work out the code to calculate the Total $ amount of products selected for an order form.

    I have pasted the form below and would greatly appreciate any help.

    <html>
    <head>
    <title>Order Form</title>
    <script language="JavaScript">
    <!--
    function validate()
    {
    if((!document.orders.firstname.value)||(!document.orders.lastname.value))
    {
    window.alert("You must enter both first and last name");
    document.orders.firstname.focus();
    return false;
    }
    else
    {
    if((!document.orders.address.value)||(!document.orders.city.value))
    {
    window.alert("You must enter an address and city details");
    document.orders.address.focus();
    return false;
    }
    else
    {
    if((isNaN(document.orders.postcode.value)==true)||(!document.orders.postcode.value))
    {
    alert("Postcode must be numbers");
    document.orders.postcode.focus();
    return false;
    }
    else
    {
    if((isNaN(document.orders.phone.value)==true)||(!document.orders.phone.value))
    {
    alert("Phone Number must be numbers");
    document.orders.phone.focus();
    return false;
    }
    else
    {
    if((isNaN(document.orders.mobile.value)==true)||(!document.orders.mobile.value))
    {
    alert("Mobile Number must be numbers");
    document.orders.mobile.focus();
    return false;
    }
    else
    {
    colouryes=false;
    for(var i=0;i<document.orders.colour.length;++i)
    {
    if(document.orders.colour[i].checked==true)
    {
    colouryes=true;
    }
    }
    if(colouryes==false)
    {
    alert("Please select a colour");
    return false;
    }
    else
    {
    return true;
    }
    }
    }
    }
    }
    }
    }

    //-->
    </script>
    </head>
    <body bg color="white" onunload="window.alert('Thank you for ordering with Yuppy Puppy.\n
    Your order will be delivered within 7 to 10 days.');">
    <h2><font color="#cc3399" font face="arial">Yuppy Puppy Order Form</font></h2>
    <br>
    <form name= orders action="mailto:smcentee@bigpond.com"
    method="post" enctype="text/plain" onsubmit="return validate();" >

    <font face="arial">
    <table>
    <tr>
    <td>First Name/td>
    <td><input name=firstname size=25 maxlength=35></td>
    </tr>
    <tr>
    <td>Last Name/td>
    <td><input name=lastname size=25 maxlength=35></td>
    </tr>
    <tr>
    <td>Address/td>
    <td><input name=address size=40></td>
    </tr>
    <tr>
    <td>City/td>
    <td><input name=city size=20></td>
    </tr>
    <tr>
    <td>Post Code/td>
    <td><input name=postcode size=4 maxlength=4></td>
    </tr>
    <tr>
    <td>Phone/td>
    <td><input name=phone size=10></td>
    </tr>
    <tr>
    <td>Mobile/td>
    <td><input name=mobile size=10></td>
    </tr>
    <tr><td><br></td></tr>
    <tr>
    <td>Pet's Name (for custom collars/tags)/td>
    <td><input name=petname size=15></td>
    </tr>
    <tr><td><br></td></tr>
    <tr>
    <td> <b>Collars</b></td>
    </tr>
    <tr>
    <td><select name=products>
    <option>Please select style
    <option value="$39.99">Collar Pink Leather $39.99
    <option value="$44.99">Collar White Rhinestones $44.99
    <option value= "$44.99">Collar Pet Name $44.99
    <option value="$24.99">Collar Flower Jewels $24.99
    </select></td>
    <td><b>Quantity<b>
    <input type=hidden name="Item" value="Name">
    <input type=text name="Qty" value="1" size="3">
    <input type=hidden name="Price" value="10">
    </td>
    </tr>
    <tr><td><br></td></tr>
    <tr>
    <td> <b>Tags</b></td>
    </tr>
    <tr>
    <td><select name=products>
    <option>Please select style
    <option value="$39.99">Rhinestone Bone $24.99
    <option value="$44.99">Black & Silver Bone $24.99
    <option value= "$44.99">Red Dog Paw $24.99
    <option value="$24.99">Black Dog Paw $24.99
    </select></td>
    <td><b>Quantity<b>
    <input type=hidden name="Item" value="Name">
    <input type=text name="Qty" value="1" size="3">
    <input type=hidden name="Price" value="10">
    </td>
    </tr>
    <tr><td><br></td></tr>
    <tr>
    <td> <b>Clothes</b></td>
    </tr>
    <tr>
    <td><select name=products>
    <option>Please select style
    <option value="$39.99">Wedding Dress $99.99
    <option value="$44.99">Flower Jumper $49.99
    <option value= "$44.99">Polka Dot Dress $35.99
    <option value="$24.99">Lucky Dog T-Shirt $24.99
    </select></td>
    <td><b>Quantity<b>
    <input type=hidden name="Item" value="Name">
    <input type=text name="Qty" value="1" size="3">
    <input type=hidden name="Price" value="10">
    </td>
    </tr>

    <tr><td><br></td></tr>
    <tr><td> <b>Colour Choices</b></td></tr>
    <tr>
    <td><p>Please select preferred colour</p>
    <input name=colour type=radio value=Red>Red<br>
    <input name=colour type=radio value=Red>White<br>
    <input name=colour type=radio value=Red>Blue<br>
    <input name=colour type=radio value=Red>Green<br>
    <input name=colour type=radio value=Red>Pink<br>
    <input name=colour type=radio value=Red>Blue<br>
    <input name=colour type=radio value=Red>Brown<br>
    <input name=colour type=radio value=Red>Cream<br>
    </td>
    </tr>

    <tr><td><br></td></tr>
    <tr>
    <td valign=top><b>Any Comments</b></td></tr>
    <td colspan=1><textarea rows=4 cols=40 name=comments wrap=virtual></textarea>
    </td>
    </tr>
    </font>

    <tr><td><br></td></tr>

    <tr><td>
    <input type = Button name = b1 value = "Calculate Total" onClick = calculate()>
    Total:
    <input type = Text name = products size = 8 value = ""></tr>
    </td>

    <tr><td><br></td></tr>
    <tr><td>
    <input type=submit value="Submit Form">
    </tr></td>
    </table>
    </form>
    </body>
    </html>

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,175
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)

    javascript numbers

    Hi Sara8, welcome to the forums,
    I'm not certain, but AFAIK the dollar sign in the values may be causing problems. Try without. BTW, please post your code inside bbtags (or turn off smilies for small examples )
    HTML Code:
    <td><select name=products>
    <option>Please select style
    <option value="39.99">Rhinestone Bone $24.99
    <option value="44.99">Black & Silver Bone $24.99
    <option value="44.99">Red Dog Paw $24.99
    <option value="24.99">Black Dog Paw $24.99
    </select></td>
    uhmm... you do know the values don't match the text?

  3. #3
    SitePoint Member
    Join Date
    Apr 2008
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sara,

    I've emailed a response and detailed reworking of the code to you at [smcentee@bigpond.com].

    If you have trouble receiving that, then I'll post the full code here.

    Let me know if you need any of that explained.

    Keep Learning!

    -A

  4. #4
    SitePoint Member
    Join Date
    Apr 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you A (medit8). You've made my day. I'm just printing out the code now and will study it closely and learn from it. Thanks for sharing your knowledge.
    S


Bookmarks

Posting Permissions

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