help with recordsets and user entered values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #16
    For qty12 though to qty2016, use either:
    [code=javascript]var qty12 = <?php echo $row_Recordset1['qty12']; ?>;[/code] or [code=javascript]var qty24 = parseFloat(docu ment.prodform.q ty24.value);[/code]but not a combination of the two like you currently have.

    Comment

    • maximillion511
      New Member
      • Jul 2008
      • 22

      #17
      acoder,
      good news!!! i got it working but there is another problem. All the qty# fields are going to be less than 2016 (the last one in the list). so is there way i can say if qty is less than 24 BUT NO MORE than 35 use this formula?
      or something similar thanks again




      Code:
      if (qty <= 12 <24) <-- this 	{ 		
      y =  qty * <?php echo $row_Recordset1['qty12']; ?>;  		document.prodform.price.value = y; 	
                                     }

      Originally posted by acoder
      For qty12 though to qty2016, use either:
      [code=javascript]var qty12 = <?php echo $row_Recordset1['qty12']; ?>;[/code] or [code=javascript]var qty24 = parseFloat(docu ment.prodform.q ty24.value);[/code]but not a combination of the two like you currently have.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #18
        Originally posted by maximillion511
        so is there way i can say if qty is less than 24 BUT NO MORE than 25 use this formula?
        Have you got the numbers right here? If it's less than 24, it's never going to be more than 25.

        Comment

        • maximillion511
          New Member
          • Jul 2008
          • 22

          #19
          see what i mean??? so that it doesnt interfere with the next recordset.




          [CODE=javascript]function getPrice(qty)


          {

          var qty = parseInt(docume nt.prodform.qua ntity.value, 10);


          var qty12 = <?php echo $row_Recordset1['qty12']; ?>;
          var qty24 = <?php echo $row_Recordset2['qty24']; ?>;
          var qty36 = <?php echo $row_Recordset3['qty36']; ?>;
          var qty72 = <?php echo $row_Recordset4['qty72']; ?>;
          var qty144 = <?php echo $row_Recordset5['qty144']; ?>;
          var qty288 = <?php echo $row_Recordset6['qty288']; ?>;
          var qty576 = <?php echo $row_Recordset7['qty576']; ?>;
          var qty1008 = <?php echo $row_Recordset8['qty1008']; ?>;
          var qty2016 = <?php echo $row_Recordset9['qty2016']; ?>;

          var y = document.prodfo rm.price.value;

          if (qty >= 12 || qty>=23) ??this one i am not sure about...
          {
          y = qty * <?php echo $row_Recordset1['qty12']; ?>;
          document.prodfo rm.price.value = y;
          }
          if(qty <= 24 || qty >= 35); {
          y = qty * <?php echo $row_Recordset2['qty24']; ?>;
          document.prodfo rm.price.value = y;
          }
          if(qty <= 36 || qty >= 71); {
          y = qty * <?php echo $row_Recordset3['qty36']; ?>;
          document.prodfo rm.price.value = y;
          }
          if(qty <= 72 || qty >= 143); {
          y = qty * <?php echo $row_Recordset4['qty72']; ?>;
          document.prodfo rm.price.value = y;
          }
          if(qty <= 144 || qty >= 287); {
          y = qty * <?php echo $row_Recordset5['qty144']; ?>;
          document.prodfo rm.price.value = y;
          }
          if(qty <= 288 || qty >= 575); {
          y = qty * <?php echo $row_Recordset6['qty288']; ?>;
          document.prodfo rm.price.value = y;
          }
          if(qty <= 576 || qty >= 1007); {
          y = qty * <?php echo $row_Recordset7['qty576']; ?>;
          document.prodfo rm.price.value = y;
          }
          if(qty <= 1008 || qty >= 2015); {
          y = qty * <?php echo $row_Recordset8['qty1008']; ?>;
          document.prodfo rm.price.value = y;
          }
          if(qty <= 2016); {
          y = qty * <?php echo $row_Recordset9['qty2016']; ?>;
          document.prodfo rm.price.value = y;
          }
          } [/CODE]




          Originally posted by acoder
          Have you got the numbers right here? If it's less than 24, it's never going to be more than 25.
          Last edited by acoder; Aug 6 '08, 05:19 PM. Reason: Please use [code] tags

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #20
            Oh, I see you've changed those else-if statements into separate if statements. Either use if-else-if or if you want them separate, use something like:
            [code=javascript]if (qty >= 12 && qty <=23)[/code]

            Comment

            • maximillion511
              New Member
              • Jul 2008
              • 22

              #21
              this things still isnt right... i really dont know why!!!!!!

              for some reason, when i enter a quantity, the only number it calculates by qty2016 value = 1.81. like it doesn't cycle thru the entire function,

              Code:
              function getPrice()   { 	 	
              var qty = parseInt(document.prodform.quantity.value, 10); 	 	 	
              var qty12 = <?php echo $row_Recordset1['qty12']; ?>; 	
              var qty24 = <?php echo $row_Recordset2['qty24']; ?>; 	
              var qty36 = <?php echo $row_Recordset3['qty36']; ?>; 	
              var qty72 = <?php echo $row_Recordset4['qty72']; ?>; 	
              var qty144 = <?php echo $row_Recordset5['qty144']; ?>; 	
              var qty288 = <?php echo $row_Recordset6['qty288']; ?>; 	
              var qty576 = <?php echo $row_Recordset7['qty576']; ?>; 	
              var qty1008 = <?php echo $row_Recordset8['qty1008']; ?>; 	
              var qty2016 = <?php echo $row_Recordset9['qty2016']; ?>; 	 	
              var y = document.prodform.price.value; 		 		 		
              
              if (qty >= 12 && qty <= 23) { 		
              y =  qty * <?php echo $row_Recordset1['qty12']; ?>  		document.prodform.price.value =y; 					    		}
              							  	 	    
              else 		{ 	 		
              if(qty <= 24 && qty >= 35) { 		
              y =  qty * <?php echo $row_Recordset2['qty24']; ?>;  		document.prodform.price.value = y; 							   						}   		 	     	   
              else 		{  		 		  				   	 		 
              if(qty <= 36 && qty >= 71) { 	 	
              y =  qty * <?php echo $row_Recordset3['qty36']; ?>; 		document.prodform.price.value = y; 							    					}    		 	    
              else 		{ 			 		 
              if(qty <= 72 && qty >= 143) { 		
              y =  qty * <?php echo $row_Recordset4['qty72']; ?>;  		document.prodform.price.value = y; 							     					}    		  	    
              else 		
              { 	 		 
              if(qty <= 144 && qty >= 287) { 		
              y =  qty * <?php echo $row_Recordset5['qty144']; ?>;  		document.prodform.price.value = y; 												      }    			  	    
              else 		
              {		 		 
              if(qty <= 288 && qty >= 575) { 		
              y =  qty * <?php echo $row_Recordset6['qty288']; ?>;  		document.prodform.price.value = y; 												      }    		  	    
              else 		
              {	 		 
              if(qty <= 576 && qty >= 1007) { 		
              y =  qty * <?php echo $row_Recordset7['qty576']; ?>;  		document.prodform.price.value = y; 														}    		  	    
              else 		
              {	 		 
              if(qty <= 1008 && qty >= 2015) { 		
              y =  qty * <?php echo $row_Recordset8['qty1008']; ?>;  		document.prodform.price.value = y; 														}    		  	    
              else 		.
              {					 		 
              if(qty <= 2016) { 		
              y =  qty * <?php echo $row_Recordset9['qty2016']; ?>;  		document.prodform.price.value = y; 					 	}   	 		} 																		   																													};   
              }

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #22
                You can't have multiple else statements, but you can have multiple else-if statements. So [code=javascript]if (cond) {
                ...
                } else if (cond) {
                ...
                } else if (cond) {
                ...
                } else {
                ...
                }[/code] would be ok, but [code=javascript]if (cond) {
                ...
                } else {
                if (cond) {
                ...
                }
                } else {
                if (cond) {
                ...
                }
                } else {
                ...
                }[/code]wouldn't be.

                Comment

                • maximillion511
                  New Member
                  • Jul 2008
                  • 22

                  #23
                  this thing still isnt right. instead of cycling thru the if else if statement it either chooses between qty12 or qty2016 and nothing in the middle and if i punch in a different number it still references it's original calculation.... here's the newest, please let me know.

                  [CODE=JavaScript]

                  if (qty <= 12 && qty >= 23) { with this one the min they can order is 12
                  y = qty * 3.17;
                  document.prodfo rm.price.value = y;
                  alert(y);

                  } else if (qty <= 24 && qty >= 35) {
                  y = qty * 2.95;
                  document.prodfo rm.price.value = y;
                  alert(y);

                  } else if (qty <= 36 && qty >= 71) {
                  y = qty * 2.72;
                  document.prodfo rm.price.value = y;
                  alert(y);

                  } else if (qty <= 72 && qty >= 143) {
                  y = qty * 2.27;
                  document.prodfo rm.price.value = y;
                  alert(y);

                  } else if (qty <= 144 && qty >= 287) {
                  y = qty * 1.94;
                  document.prodfo rm.price.value = y;
                  alert(y);

                  } else if (qty <= 288 && qty >= 575) {
                  y = qty * 1.92;
                  document.prodfo rm.price.value = y;
                  alert(y);

                  } else if(qty <= 576 && qty >= 1007){
                  y = qty * 1.88;
                  document.prodfo rm.price.value = y; alert(y);

                  } else if (qty <= 1008 && qty >= 2015) {
                  y = qty * 1.85;
                  document.prodfo rm.price.value = y; alert(y);

                  } else if (qty <= 2016){
                  y = qty * 1.81;
                  document.prodfo rm.price.value = y;
                  alert(y);

                  }

                  [/CODE]




                  Originally posted by acoder
                  You can't have multiple else statements, but you can have multiple else-if statements. So [code=javascript]
                  if (cond) {
                  ...
                  } else if (cond) {
                  ...
                  } else if (cond) {
                  ...
                  } else {
                  ...
                  }[/code] would be ok, but [code=javascript]if (cond) {
                  ...
                  } else {
                  if (cond) {
                  ...
                  }
                  } else {
                  if (cond) {
                  ...
                  }
                  } else {
                  ...
                  }[/code]wouldn't be.
                  Last edited by acoder; Aug 7 '08, 03:30 PM. Reason: fixed code tags

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #24
                    I think the logic has gone a bit awry. You need to swap the <= and >= around, so [code=javascript]if (qty <= 12 && qty >= 23) { [/code]becomes [code=javascript]if (qty >= 12 && qty <= 23) { [/code]

                    Comment

                    • maximillion511
                      New Member
                      • Jul 2008
                      • 22

                      #25
                      but that doesnt explain why it only uses the qty2016 value.

                      the first one has to be if qty greater than or equal to12 and is also less than 23, calculate the quantity by 3.17 (php echo recordset1)

                      if quantity is greater than or equal to 24 and is also less than or equal to 35, calculate quantity by 2.95 (php echo recordset2)

                      and so on til it gets to 2016. also something else that has me confused is why it doesnt redo it if the quantity number is changed at anytime.


                      Originally posted by acoder
                      I think the logic has gone a bit awry. You need to swap the <= and >= around, so [code=javascript]if (qty <= 12 && qty >= 23) { [/code]becomes [code=javascript]if (qty >= 12 && qty <= 23) { [/code]

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #26
                        The reason why it only gives the qty2016 value is because that's the only condition that can be met. Think about it. If you have qty <=12 and qty >=23, then the qty value has to be less than or equal to 12 AND greater than or equal to 23 which is impossible!

                        Comment

                        • maximillion511
                          New Member
                          • Jul 2008
                          • 22

                          #27
                          ok acoder, how about this?

                          could i do qty <= 12 && qty > 24?

                          that way the logic would be asking if this quantity is in between these two numbers? would that be possible???

                          Comment

                          • acoder
                            Recognized Expert MVP
                            • Nov 2006
                            • 16032

                            #28
                            No, see post #24. It should be qty >= 12 && qty < 24

                            Comment

                            • maximillion511
                              New Member
                              • Jul 2008
                              • 22

                              #29
                              IT WORKS! acoder, thanks for all your help you have no idea how much i really appreciate it.

                              thanks to bytes for having ppl on here like you that we can talk to inorder to get help.

                              this will be the last question for this thread. is there any way i can "fix" the decimals to two places? sometimes i ll get a value that looks like this: 1586.7199999999 998 instead of making it 1586.72.



                              Originally posted by acoder
                              No, see post #24. It should be qty >= 12 && qty < 24

                              Comment

                              • acoder
                                Recognized Expert MVP
                                • Nov 2006
                                • 16032

                                #30
                                Glad to hear that it's working.

                                As for the last question, use the toFixed() method.

                                Comment

                                Working...