SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Mad Beach Bum jgsketch's Avatar
    Join Date
    Aug 2002
    Location
    FL
    Posts
    825
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lost in Calculations

    Hello guys,
    I have a wapper here, and I'm going crossed eyed trying to figure this one out. I have a form with Radio Buttons for my customers to purchase a customizable club program. I have 5 sections each of which cost a certain amount. Then I have another section that lets the user pick what duration they would like, 3, 6, 9 and 12 months. Each option has a certain % taken off the retail price. 5%, 10%, 15%, 20% depending on the duration option. All calculations are done on the fly as customers click the radio buttons. I do have it set up and working, only I have the duration listed as many times as my sections. I would like to have only one duration section. I'm not sure if this is done in java or HTML. My page is HERE . I just need to be guided a little on where to start. Any help would be great. Thanks

    Script that I'm currently using
    HTML Code:
    <script type="text/javascript">
    function Dollar (val) {  // force to valid dollar amount
    var str,pos,rnd=0;
      if (val < .995) rnd = 1;  // for old Netscape browsers
      str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
      pos = str.indexOf (".");
      if (pos > 0) str = str.substring (rnd, pos + 3);
      return str;
    }
    function ReadForm (obj1, tst) { // process radio and checkbox
    var i,amt,des,obj,pos,val;
      amt = obj1.baseamt.value*1.0;	// base amount
      des = obj1.basedes.value;		// base description
      for (i=0; i<obj1.length; i++) {  // run entire form
    	obj = obj1.elements[i];		// a form element
    	if (obj.type == "checkbox" ||  // checkboxes
    		obj.type == "radio") {	 //  and radios
    	  if (obj.checked) {		   // did user check it?
    		val = obj.value;		   // the value of the selection
    		pos  = val.indexOf ("@");  // price set?
    		if (pos > 0) amt = val.substring (pos + 1)*1.0;
    		pos  = val.indexOf ("+");  // price increment?
    		if (pos > 0) amt = amt + val.substring (pos + 1)*1.0;
    		pos  = val.indexOf ("%");  // percent change?
    		if (pos > 0) amt = amt + (amt * val.substring (pos + 1)/100.0);
    		if (des.length == 0) des = val;
    		else des = des + ", " + val;  // accumulate value
    	  }
    	}
      }
      obj1.item_name.value = des;
      obj1.amount.value = Dollar (amt);
      if (obj1.tot) obj1.tot.value = "$" + Dollar (amt);
    }
    </script>
    Form that I'm using
    HTML Code:
    <form target="paypal" action="[url=https://www.paypal.com/cgi-bin/webscr]https://www.paypal.com/cgi-bin/webscr[/url]" method="post" onsubmit="return ReadForm(this, true);">
    <input type="hidden" name="baseamt" value="0.00" />
    <input type="hidden" name="basedes" value="Test Item @0.00" />
    <table><tr><td width="200" valign="top">
    <p>Option One<br>
       <input type="radio" name="option1" value="a" checked="checked" />A. None<br>
       <input type="radio" name="option1" value="b" />B. 2 Votives<br>
       <input type="radio" name="option1" value="c" />C. Shaped Tarts (20) pieces<br>
    <br><br>Option Two<br>
       <input type="radio" name="option2" value="a" checked="checked" />A. None<br>
       <input type="radio" name="option2" value="b" />B. 6 Votives<br>
       <input type="radio" name="option2" value="c" />C. Candle of the Month<br>
    <br><br>Option Three<br>
       <input type="radio" name="option3" value="a" checked="checked" />A. None<br>
       <input type="radio" name="option3" value="b" />B. 5oz Jar Candle<br>
       <input type="radio" name="option3" value="c" />C. 3"x6" Pillar<br>
    <br><br>Option Four<br>
       <input type="radio" name="option4" value="a" checked="checked" />A. None<br>
       <input type="radio" name="option4" value="b" />B. 10oz Jar Candle<br>
       <input type="radio" name="option4" value="c" />C. Two 3"x4" Pillars<br>
    <br>Option Five<br>
       <input type="radio" name="option5" value="a" checked="checked" />A. None<br>
       <input type="radio" name="option5" value="b" />B. 16oz Jar Candle<br>
       <input type="radio" name="option5" value="c" />C. 3"x9" Pillar<br>
       <br></p>
       </td><td valign="top" width="150">
       <p>
    <input type="radio" name="time1" value="option13 +8.55" onclick  = "ReadForm (this.form, false);"/>3 Months = $8.55<br>
    <input type="radio" name="time1" value="option16 +16.20" onclick  = "ReadForm (this.form, false);"/>6 Months = $16.20<br>
    <input type="radio" name="time1" value="option19 +22.95" onclick  = "ReadForm (this.form, false);"/>9 Months = $22.95<br>
    <input type="radio" name="time1" value="option112 +28.80" onclick  = "ReadForm (this.form, false);"/>12 Months = $28.80<br>
    			  <br><br>
    <input type="radio" name="time2" value="option23 +17.10" onclick  = "ReadForm (this.form, false);"/>3 Months = $17.10<br>
    <input type="radio" name="time2" value="option26 +32.40" onclick  = "ReadForm (this.form, false);"/>6 Months = $32.40<br>
    <input type="radio" name="time2" value="option29 +45.90" onclick  = "ReadForm (this.form, false);"/>9 Months = $45.90<br>
    <input type="radio" name="time2" value="option212 +57.60" onclick  = "ReadForm (this.form, false);"/>12 Months = $57.60<br>
    			  <br><br>
    <input type="radio" name="time3" value="option33 +22.80" onclick  = "ReadForm (this.form, false);"/>3 Months = $22.80<br>
    <input type="radio" name="time3" value="option36 +43.20" onclick  = "ReadForm (this.form, false);"/>6 Months = $43.20<br>
    <input type="radio" name="time3" value="option39 +61.20" onclick  = "ReadForm (this.form, false);"/>9 Months = $61.20<br>
    <input type="radio" name="time3" value="option312 +76.80" onclick  = "ReadForm (this.form, false);"/>12 Months = $76.80<br>
    			  <br><br>
    <input type="radio" name="time4" value="option43 +34.20" onclick  = "ReadForm (this.form, false);"/>3 Months = $34.20<br>
    <input type="radio" name="time4" value="option46 +64.80" onclick  = "ReadForm (this.form, false);"/>6 Months = $64.80<br>
    <input type="radio" name="time4" value="option49 +91.80" onclick  = "ReadForm (this.form, false);"/>9 Months = $91.80<br>
    <input type="radio" name="time4" value="option412 +115.20" onclick  = "ReadForm (this.form, false);"/>12 Months = $115.20<br>
    			  <br><br>
    <input type="radio" name="time5" value="option53 +42.75" onclick  = "ReadForm (this.form, false);"/>3 Months = $42.75<br>
    <input type="radio" name="time5" value="option56 +81.00" onclick  = "ReadForm (this.form, false);"/>6 Months = $81.00<br>
    <input type="radio" name="time5" value="option59 +114.75" onclick  = "ReadForm (this.form, false);"/>9 Months = $114.75<br>
    <input type="radio" name="time5" value="option512 +144.00" onclick  = "ReadForm (this.form, false);"/>12 Months = $144.00<br>
    Item Total 
    <input type="text" name="tot" value="$0.00" size ="10" /><br>
    <input type="submit" value="Add to Cart" border="0" name="submit" />
    <input type	= "button"
    	   value   = "Reset Form"
    	   onclick = "this.form.reset ();" /></p>	  
    </td></tr></table></form>
    As you can see, I only need one of the five duration section that are listed at the bottom of the code. It's just the matter of taking the unit price * months * %. But that is the part I'm having problem with.

  2. #2
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You seem to be making it awfully complicated. Wouldn't you be better having one drop-down for all the options and one drop-down for the durations?

    That way you wouldn't need to have "None" as the default selection in each of your subsections which - IMO - looks a bit odd.


    Andy
    From the English nation to a US location.


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
  •