Jump to content

I need a little help with a form


Stonedonspam

Recommended Posts

I am trying to make a simple order form to put on my site, but I don't need anything too fancy. I need some help on making a drop down menu, or preferably, a form that will let you know how much of a product the person wants. You just type in the number and it says the total at the bottom.Basically, all I have been trying to was get ideas from forms and scripts already made, but I haven't found anything that will work. Here is the link to the form so far. I've been able to get it to work with checkboxes, but haven't had luck with those text boxes. If anyone can give me a little help with this, I would really appreciate it. Click here for the orderform... so farHere is the script for it also:

<script language="JavaScript"><!-- hide contents from old browsersfunction tally()        {        Cost = 0;        if (document.orderform.Item1.checked) { Cost = Cost + 12;}        if (document.orderform.Item2.checked) { Cost = Cost + 24;} if (document.orderform.number.?) { Cost = Cost + 10;}         Cost = dollar(Cost);              document.orderform.Total.value = "$" + Cost;        }function dollar (amount){        amount = parseInt(amount * 100);        amount = parseFloat(amount/100);        if (((amount) == Math.floor(amount)) && ((amount - Math.floor (amount)) == 0))        {                amount = amount + ".00"                return amount;        }        if ( ((amount * 10) - Math.floor(amount * 10)) == 0)        {                amount = amount + "0";                return amount;        }        if ( ((amount * 100) - Math.floor(amount * 100)) == 0)        {                amount = amount;                return amount;        }        return amount;}//--></script><center><h1>Order Form</h1></center><p>Click the products that you want and press "Send Order".<form method="post" name="orderform" onkeydown="return validate()" action="http://cgi.freedback.com/mail.pl"><input type=hidden name=to value="Myemailaddress"><table border="0">    <tr><td colspan="4"></tr> <tr><td colspan="2"><input type="number" name="number" maxLength="1" size="1" id="number" onKeyPress="tally()"> Product 1</td><tr><td><input type="checkbox" name="Item1" value="1 Product1_chosen" onclick="tally()"> 1 ($12)</td><td><input type="checkbox" name="Item2" value="2 Product2_chosen" onclick="tally()"> 2 ($24)</td></tr><tr><td> Total <input type="text" name="Total" readOnly="yes" value="$0" size="7"></td></tr>THIS IS WHERE THE CONTACT INFORMATION GOES, BUT SINCE IT DOESN'T NEED TO IMPROVED AND TAKES UP A LOT OF ROOM, I LEFT IT OUT.      <tr><td colspan="4" height="3"><hr></td></tr>      <tr><td colspan="2" align="center"><input type="Submit" value="Send Order"></td><td colspan="2" align="center"><input type="RESET" value="Reset Order"></td></tr>  </table></form>
Link to comment
Share on other sites

Here are some ideas that might help.You can create an array and loop through and add the values for each product:

<html><head>  <title></title><script type="text/javascript">var tm = null;var prev_total;  //kills flickervar fields = ['Item1', 'Item2'];var m = [12.25, 14.50];function tally(){var form = document.forms['orderform'];var total = 0;    for(var j = 0; j < fields.length; j ++){        var f_field_v = form.elements[fields[j]].value;        total += (parseInt(f_field_v)|| 0) * m[j];        }        if(total != prev_total){        prev_total = total;                form.elements['Total'].value = '$' + total.toFixed(2);        }        }function start(){tm = setInterval('tally()', 100);}</script></head><body onload="start()"><center><h1>Order Form</h1></center><form method="post" name="orderform"><input type=hidden name=to value="Myemailaddress"><table border="0">    <tr><td colspan="4"></tr><tr><td colspan="2"> </td><tr><td><input type="text" name="Item1" size="3" /> P1 Cost ea. $12.25<br /><input type="text" name="Item2" size="3" /> P2 Cost ea. $14.50</tr><tr><td> Total <input type="text" name="Total" readOnly="yes" value="$0" size="7" /></td></tr><table></body></html>

Post back if it needs tweaking.Thanks,

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...