Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Group sting problem

    Ok, will try and explain this as best i can, i want this line of code

    Code:
    if (days < 84 && days > 60 && total > testc && groupstring =="Array[12]" ) {total = groupstring[11]} //12week fix
    To only run if groupstring 12 is being used. the code i have used dose not work ( Assuming groupstring =="Array[12]" is wrong). Can anyone help me out



    Full code for reference
    Code:
    // price calculation
    function calculate() {
    	// use get month 
        var month = new Date().getMonth();
    
         var d1 = document.date.firstDate.value;
         var d2 = d1.replace(/^(\d{1,2}\/)(\d{1,2}\/)(\d{4})$/, "$2$1$3");
         var d3 = new Date(d2);
    month = d3.getMonth();
    
    		var days = parseInt('0' + document.date.days.value, 10),
    			groupstring, total = 0;
    // 1 day, 2 days, 3 days, 4 days, 5 days, 6 days, 7 days, 28 DaySummer, 28 DayWinter, Excess Amount, excess mile, 12week
    		switch (document.date.car.value) {
    			
    			case 'B': groupstring = '2650,5300,7950,10600,13250,13500,14500,48000,46000,25000,10,44000';  break;//CLIO 3/5 -->
    			case 'B2': groupstring = '2650,5300,7950,10600,13250,13500,14500,48000,46000,25000,10,44000';  break;//MAN PICANTO -->
    			case 'CD': groupstring = '2800,5600,8400,11200,14000,14500,15500,49900,48000,25000,10,46000';  break;// RIO MANUAL-->
    			case 'CD2': groupstring = '2800,5600,8400,11200,14000,14500,15500,49900,48000,25000,10,46000';  break;//CORSA -->
    			case 'CD3': groupstring = '2800,5600,8400,11200,14000,14500,15500,49900,48000,25000,10,46000';  break;// PICANTO AUTO-->
                case 'CD4': groupstring = '2800,5600,8400,11200,14000,14500,15500,49900,48000,25000,10,44000';  break;// 500-->
    			case 'E': groupstring = '3000,6000,9000,12000,15000,15500,16500,53500,51000,25000,10,44000';  break;// VENGA MANUAL -->
    			case 'E2': groupstring = '3000,6000,9000,12000,15000,15500,16500,53500,51000,25000,10,48000';  break;// RIO AUTO-->
    			case 'F': groupstring = '3200,6400,9600,12800,16000,17000,17500,58000,54000,25000,15,44000';  break;// FOCUS-->
    			case 'F2': groupstring = '3200,6400,9600,12800,16000,17000,17500,58000,54000,25000,15,44000';  break;// MEGANE-->
    			case 'F3': groupstring = '3200,6400,9600,12800,16000,17000,17500,58000,54000,25000,15,48000';  break;// CEED-->
    			case 'F4': groupstring = '3200,6400,9600,12800,16000,17000,17500,58000,54000,25000,15,44000';  break;// I30-->
    			case 'F5': groupstring = '3200,6400,9600,12800,16000,17000,17500,58000,54000,25000,15,50000';  break;// VENGA AUTO-->
    			case 'G': groupstring = '3500,7000,10500,14000,17500,19000,20000,62000,59000,25000,15,54000'; break;//CEED ESTATE -->
    			case 'G2': groupstring = '3500,7000,10500,14000,17500,19000,20000,62000,59000,40000,15,54000'; break;//SPORT PET -->
    			case 'H': groupstring = '3800,7600,11400,15200,19000,21500,22500,72000,62000,25000,15,44000'; break;// -MONDEO->
    			case 'I': groupstring = '3800,7600,11400,15200,19000,21500,22500,72000,62000,25000,15,58000'; break;//2WD SPORTAGE -->
    			case 'J': groupstring = '4500,9000,13500,18000,22500,24000,25000,75000,65000,40000,15,60000'; break;//4WD SPORTAGE -->
    			case 'J2': groupstring = '4500,9000,13500,18000,22500,24000,25000,75000,65000,40000,15,44000'; break;//OPTIMA -->
    			case 'J3': groupstring = '5000,9000,13500,18000,22500,24000,25000,75000,65000,40000,15,44000'; break;//IX35 -->
    			case 'K': groupstring = '6500,11000,16500,22000,27500,30000,31000,95000,82500,40000,15,44000'; break;//GALAXY -->
    			case 'K2': groupstring = '6500,11000,16500,22000,27500,30000,31000,95000,82500,40000,15,44000'; break;//RCZ -->
    			case 'L': groupstring = '7000,12000,18000,24000,30000,35000,36000,120000,120000,40000,15,100000'; break;// SORENTO-->
    			case 'L2': groupstring = '7000,12000,18000,24000,30000,35000,36000,120000,120000,40000,15,100000'; break;// I800-->
    			case 'L3': groupstring = '4500,9000,13500,18000,22500,24000,25000,75000,65000,40000,15,60000'; break;//carens -->
    			case 'M': groupstring = '2650,5300,7950,10600,13250,14600,15000,49900,48000,25000,10,44000'; break;// KANGOO-->
    			case 'N': groupstring = '2800,5600,8400,11200,14000,14500,15500,49900,48000,25000,10,46000'; break;// nv200-->
    			case 'O': groupstring = '4100,8200,12300,16400,20500,20800,21000,70000,70000,40000,15,62500'; break;// TRAFIC-->
    		}
    		groupstring = groupstring.split(',');
    		if (days > 0 && days < 8) {total =  groupstring[days - 1];     } else
    		if (days < 28)            {total = (groupstring[6] / 7) * days;} else
    		if (days === 28)          {total =  groupstring[8];}
    		if (days > 28 && days < 84)   		  {total =(groupstring[8] / 28) * days;}
    		if (days === 84)          {total =  groupstring[11] * 3;}
    		if (days > 84)   		  {total =(groupstring[11] / 28) * days;}
    		if (month > 1 && month < 9 && days == 28) {total = groupstring[7];} // if jan or feb or oct, nov, dec then summer
    		if (month > 1 && month < 9 && days > 28 && days < 84) {total =(groupstring[7] / 28) * days;}
    		
    
    	var testa = parseInt(groupstring[8])
    	var testb = parseInt(groupstring[7])
    	var testc = parseInt(groupstring[11])
    
    	
    	    
    if (days < 28 && total > testa && month < 2 ) {total = groupstring[8]} // winter
    if (days < 28 && total > testa && month > 8 ) {total = groupstring[8]} // winter
    if (days < 28 && total > testb && month > 1 && month < 9 && days < 84 ) {total = groupstring[7]} // summer
    if (days < 84 && days > 60 && total > testc && groupstring =="Array[12]" ) {total = groupstring[11]} //12week fix
    				
    				
    				
    				
    				
    		
    	
    			document.date.rentalamount.value = "£" + (Math.round(total) / 100).toFixed(2);
    			
    var ee = document.date.rentalamount.value
    var er = (ee.slice(1))
    var rre = er/days
    var rree = rre * 28
    
    document.date.price4.value = "£" + rree.toFixed(2)
    
    		}

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,930
    Thanks
    56
    Thanked 550 Times in 547 Posts
    you understand that "Array[12]" is a string, and therefore will be exactly that - "Array[12]". There's nothing in your code that makes me think that groupstring could ever be equal to the string value "Array[12]". What are you testing for here - what do you want groupstring to be at that point?

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Right, this script is for a car hire price calculator. When a hire goes over 84 days, you then get it at a reduced price, the person im doing the website for wants it so that if the hire is less than 84 days, it dose not go over the price for 84 days ,

    So for example

    Code:
    case 'B2': groupstring = '2650,5300,7950,10600,13250,13500,14500,48000,46000,25000,10,44000';  break;//MAN PICANTO -->
    the 84 day price is 440 per week, but if you select 83 days, for example, you get a higher price, i need the script to make it so that dose not happen

  • #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,930
    Thanks
    56
    Thanked 550 Times in 547 Posts
    but what is the additional test you are making? From what you say, this should be enough, shouldn't it?
    Code:
    if (days < 84 && days > 60 && total > testc ) {total = groupstring[11]}


  •  

    Posting Permissions

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