Hi,
I'm struggling getting this dropdown method to work. I just can't seem to make it switch when selecting value 4. Could someone please help me. I'm using version 3.1 RC5.5. Here is my code:
This is my HTML - Main onLoad/View Code
<?php date_default_timezone_set('Pacific/Auckland'); ?>
<h1>Get a free quote...</h1>
<?php
if($_GET['From_Day']==NULL){
$current_day=date("d");
}
else{
$current_day=htmlspecialchars($_GET['From_Day']);
}
if($_GET['From_Month']==NULL){
$current_month=date("m")-1;
}
else{
$current_month=htmlspecialchars($_GET['From_Month']);
}
if($_GET['From_Year']==NULL){
$current_year=date("Y");
}
else{
$current_year=htmlspecialchars($_GET['From_Year']);
}
$to_day=htmlspecialchars($_GET['To_Day']);
$to_month=htmlspecialchars($_GET['To_Month']);
$to_year=htmlspecialchars($_GET['To_Year']);
$months=array(0=>'January',1=>'February',2=>'March',3=>'April',4=>'May',5=>'June',6=>'July',7=>'August',8=>'September',9=>'October',10=>'November',11=>'December');
$locations=array('Christchurch'=>0,'Auckland'=>250,'Queenstown'=>180,'Nelson'=>180);
?>
<fieldset>
<!--=== Vehicle Types ===-->
<div>
<label for="Van_Type">Van Type</label>
<select size="1" name="Van_Type" id="Van_Type">
<option value="" selected="selected">Select</option>
<option value="1">2/3 Berth Sportster Camper</option>
<option value="2">2/3 Berth Clubby Camper</option>
<option value="3">4 Berth Motorhome</option>
<option value="4">Economy Vehicle</option>
<option value="5">Tourist Vehicle</option>
<option value="6">Touring Wagon</option>
<option value="7">Premium Vehicle</option>
<option value="8">People Mover</option>
</select>
</div>
<!--=== From Date ===-->
<div>
<label for="From_Day">Pick up</label>Day
<select size="1" name="From_Day">
<?php
for($day=1; $day<=31; $day++)
{
$thisday="<option ";
$thisday.="value=".$day." ";
if($day==$current_day)
{
$thisday.="selected='selected' ";
}
$thisday.=">".$day."</option>";
echo $thisday;
}
?>
</select>
Month <select size="0" name="From_Month">
<?php
foreach($months as $pos=>$name)
{
$thismonth="<option value={$pos} ";
if($pos==$current_month)
{
$thismonth.="selected='selected' ";
}
$thismonth.=">".$name."</option>";
echo $thismonth;
}
?>
</select>
Year
<select size="1" name="From_Year">
<?php
for($year=date("Y"); $year<$current_year+2; $year++)
{
$thisyear="<option ";
if($year==$current_year)
{
$thisyear.="selected='selected' ";
}
$thisyear.="value=".$year." ";
$thisyear.=">".$year."</option>";
echo $thisyear;
}
?>
</select>
Location
<select size="1" name="pickup" disabled="disabled">
<?php
foreach($locations as $place=>$cost)
{
$thisplace="<option value={$place} ";
if($place==htmlspecialchars($_GET['pickup']))
{
$thisplace.="selected='selected' ";
}
$thisplace.=">".$place."</option>";
echo $thisplace;
}
?>
</select>
</div>
<!--=== To Date ===-->
<div>
<label for="To_Day">Drop off</label>
Day
<select size="1" name="To_Day">
<?php
for($day=1; $day<=31; $day++)
{
$thisday="<option ";
$thisday.="value=".$day." ";
if($day==$to_day)
{
$thisday.="selected='selected' ";
}
elseif($to_day==NULL)
{
if($day==$current_day+1)
{
$thisday.="selected='selected' ";
}
}
$thisday.=">".$day."</option>";
echo $thisday;
}
?>
</select>
Month <select size="0" name="To_Month">
<?php
foreach($months as $pos=>$name)
{
$thismonth="<option value={$pos} ";
if($pos==$to_month)
{
$thismonth.="selected='selected' ";
}
elseif($to_month==NULL)
{
if($pos==$current_month)
{
$thismonth.="selected='selected' ";
}
}
$thismonth.=">".$name."</option>";
echo $thismonth;
}
?></select>
Year
<select size="1" name="To_Year">
<?php
for($year=date("Y"); $year<$current_year+2; $year++)
{
$thisyear="<option ";
$thisyear.="value=".$year." ";
if($year==$to_year)
{
$thisyear.="selected='selected' ";
}
$thisyear.=">".$year."</option>";
echo $thisyear;
}
?>
</select>
Location
<select size="1" name="dropoff">
<?php
foreach($locations as $place=>$cost)
{
$thisplace="<option value={$place} ";
if($place==htmlspecialchars($_GET['dropoff']))
{
$thisplace.="selected='selected' ";
}
$thisplace.=">".$place."</option>";
echo $thisplace;
}
?>
</select>
</div>
</fieldset>
<fieldset>
<!--=== Optional Extras ===-->
<div>
<label for="gps">G.P.S</label>
<input type="checkbox" name="gps" />
<span>($50 per hire)</span>
</div>
<div>
<label for="Bikes">Bikes</label>
<select size="1" name="Bikes">
<option value="0" selected="selected">0</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
(All Campers)
</div>
<div>
<label for="Kayaks">Kayaks</label>
<select size="1" name="Kayaks">
<option value="0" selected="selected">0</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
(Sportster Only)
</div>
<div>
<label for="DVD">DVD Player</label>
<input type="checkbox" name="DVD" />
<span>($50 per hire)</span>
</div>
<div>
<label for="Ski_Racks">Ski Racks</label>
<input type="checkbox" name="Ski_Racks" />
<span>($50 per hire)</span>
</div>
<div>
<label for="portaloo">Porta Loo</label>
<input type="checkbox" name="portaloo" />
<span>($50 per hire)</span>
</div>
<div>
<label for="snowchains">Snow Chains</label>
<input type="checkbox" name="snowchains" />
<span>($50 per hire)</span>
</div>
<div>
<label for="babyseat">Baby Seat</label>
<input type="checkbox" name="babyseat" />
<span>($50 per hire)</span>
</div>
<div>
<label for="boosterseat">Booster Seat</label>
<input type="checkbox" name="boosterseat" />
<span>($50 per hire)</span> 4-7 years old
</div>
</fieldset>
<fieldset>
<div>
<input onClick="quoteNow()" type="button" value="Get/Refresh Quote" name="Go" />
</div>
<div>
<label for="Quote_Result">Quote Breakdown</label>
<textarea name="Quote_Result" rows="8" cols="40"></textarea>
</div>
<div>
<label for="Total">Total Cost</label>
<input style="float: left;" type="text" size="14" value="$0.00 NZD" name="Total" />
</div>
<div style="margin-left:130px; padding-top:13px"><img src="images/cards.png" width="123" height="19" /><span style="font-size:9px; color:#555555">*Available from the 15<sup>th</sup> Apr - 30<sup>th</sup> Oct. Subject to availability</span></div>
<div style="margin-top:15px">
<input type="image" name="Print" src="images/printquote.jpg" onclick="printField(); return false;" id="Printquote" />
<input type="image" name="BookNow" src="images/booknow.jpg" onclick="goToURL(); return false;" id="Booknow" />
</div></fieldset>
And this is what I have in my Javascript - Main onLoad/View Code
<?php
global $mainframe;
$case = JRequest::getString(Van_Type', '', 'post');
switch ($Van_Type) {
case '1':
default:
$url = 'quote_form1';
break;
case '2':
default:
$url = 'quote_form1';
break;
case '3':
default:
$url = 'quote_form1';
break;
case '4':
default:
$url = 'cars_quote';
break;
case '5':
$url = 'cars_quote';
break;
case '6':
$url = 'cars_quote';
break;
case '7':
$url = 'cars_quote';
break;
case '8':
$url = 'cars_quote';
break;
}
$url = 'index.php?option=com_chronocontact&chronoformname='.$url;
$mainframe->redirect($url);?>
var totalPrice = 0
var totalDays;
function roundNumber(num, dec) {
var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
return result;
}
function extracost(oneCost,twoCost,threeCost){
if(vehicletype==1)
{
xtraCost=oneCost;
}
else if(vehicletype==2)
{
xtraCost=twoCost;
}
else if(vehicletype==3)
{
xtraCost=threeCost;
}
return xtraCost;
}
function goToURL()
{
quoteNow();
var tg = "https://www.roadrunnerrentals.co.nz/index.php?Itemid=5&option=com_chronocontact&chronoformname=booking_form&Total="+totalPrice+
"&From_Day=" + document.getElementById("ChronoContact_quote_form").From_Day.value +
"&From_Month=" + document.getElementById("ChronoContact_quote_form").From_Month.value +
"&From_Year=" + document.getElementById("ChronoContact_quote_form").From_Year.value +
"&To_Day=" + document.getElementById("ChronoContact_quote_form").To_Day.value +
"&To_Month=" + document.getElementById("ChronoContact_quote_form").To_Month.value +
"&To_Year=" + document.getElementById("ChronoContact_quote_form").To_Year.value +
"&Van_Type=" + document.getElementById("ChronoContact_quote_form").Van_Type.value +
"&Bikes=" + document.getElementById("ChronoContact_quote_form").Bikes.value +
"&dropoff=" + document.getElementById("ChronoContact_quote_form").dropoff.value +
"&Kayaks=" + document.getElementById("ChronoContact_quote_form").Kayaks.value;
if (document.getElementById("ChronoContact_quote_form").DVD.checked)
{
tg = tg + "&DVD=" + document.getElementById("ChronoContact_quote_form").DVD.checked;
}
if (document.getElementById("ChronoContact_quote_form").Ski_Racks.checked)
{
tg = tg + "&Ski_Racks=" + document.getElementById("ChronoContact_quote_form").Ski_Racks.checked;
}
if (document.getElementById("ChronoContact_quote_form").gps.checked)
{
tg = tg + "&gps=" + document.getElementById("ChronoContact_quote_form").gps.checked;
}
if (document.getElementById("ChronoContact_quote_form").portaloo.checked)
{
tg = tg + "&portaloo=" + document.getElementById("ChronoContact_quote_form").portaloo.checked;
}
if (document.getElementById("ChronoContact_quote_form").snowchains.checked)
{
tg = tg + "&snowchains=" + document.getElementById("ChronoContact_quote_form").snowchains.checked;
}
if (document.getElementById("ChronoContact_quote_form").babyseat.checked)
{
tg = tg + "&babyseat=" + document.getElementById("ChronoContact_quote_form").babyseat.checked;
}
if (document.getElementById("ChronoContact_quote_form").boosterseat.checked)
{
tg = tg + "&boosterseat=" + document.getElementById("ChronoContact_quote_form").boosterseat.checked;
}
if(totalDays<5)
{
alert("Your booking is too short, the minimum hire period is 5 days. Please adjust your dates and try again.")
}
else{
top.location = tg;
}
}
function quoteNow()
{
var oneday = 1000*60*60*24;
var fromDate = new Date(document.getElementById("ChronoContact_quote_form").From_Year.value,document.getElementById("ChronoContact_quote_form").From_Month.value,document.getElementById("ChronoContact_quote_form").From_Day.value);
var todaysDate= new Date();
var toDate = new Date();
var tempDate = new Date();
var p1Days;
var p2Days;
var quoteText = "";
var vehiclePrice = 0;
var bikePrice = 0;
var kayakPrice = 0;
var DVDPrice = 0;
var SkiRackPrice = 0;
var dropoffPrice = 0;
var gpsPrice = 0;
var portalooPrice = 0;
var snowchainsPrice = 0;
var boosterseatPrice = 0;
var babyseatPrice = 0;
var xtraCost = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//WORKING OUT THE DIFFERENCE BETWEEN TODAYS DATE AND THE START OF THE BOOKING
var todayms = todaysDate.getTime();
var tillms = fromDate.getTime();
// Calculate the difference in milliseconds
var difference_ms = Math.abs(todayms - tillms);
// Convert back to days and return
var daysOut= Math.floor(difference_ms/oneday);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
toDate.setMonth(document.getElementById("ChronoContact_quote_form").To_Month.value) ;
toDate.setDate(document.getElementById("ChronoContact_quote_form").To_Day.value) ;
toDate.setYear(document.getElementById("ChronoContact_quote_form").To_Year.value) ;
totalDays = Math.ceil((toDate.getTime() - fromDate.getTime()) / oneday) ;
vehicletype = document.getElementById("ChronoContact_quote_form").Van_Type.value;
if (totalDays < 0)
{
totalDays = 0 ;
}
tempDate = fromDate ;
for (i = 0; i < totalDays; i++)
{
tempDate.setTime(tempDate.getTime() + oneday) ;
if (tempDate.getMonth() ==0)
{
//January
xtraCost=extracost(115,135,215);
vehiclePrice = vehiclePrice + xtraCost;
}
else if (tempDate.getMonth() ==1)
{
//February
xtraCost=extracost(115,135,215);
vehiclePrice = vehiclePrice + xtraCost;
}
else if (tempDate.getMonth() ==2)
{
//March
xtraCost=extracost(115,135,215);
vehiclePrice = vehiclePrice + xtraCost;
}
else if (tempDate.getMonth() ==3)
{
//April
xtraCost=extracost(65,69,175);
vehiclePrice = vehiclePrice + xtraCost;
}
else if (tempDate.getMonth() ==4)
{
//May
xtraCost=extracost(49,49,125);
vehiclePrice = vehiclePrice + xtraCost;
}
else if (tempDate.getMonth() ==5)
{
//June
xtraCost=extracost(49,49,125);
vehiclePrice = vehiclePrice + xtraCost;
}
else if (tempDate.getMonth() ==6)
{
//July
xtraCost=extracost(49,49,125);
vehiclePrice = vehiclePrice + xtraCost;
}
else if (tempDate.getMonth() ==7)
{
//August
xtraCost=extracost(49,49,125);
vehiclePrice = vehiclePrice + xtraCost;
}
else if (tempDate.getMonth() ==8)
{
//September
xtraCost=extracost(49,49,125);
vehiclePrice = vehiclePrice + xtraCost;
}
else if (tempDate.getMonth() ==9)
{
//October
xtraCost=extracost(65,65,175);
vehiclePrice = vehiclePrice + xtraCost;
}
else if (tempDate.getMonth() ==10)
{
//November
xtraCost=extracost(85,85,175);
vehiclePrice = vehiclePrice + xtraCost;
}
else if (tempDate.getMonth() ==11)
{
//December
xtraCost=extracost(115,135,215);
vehiclePrice = vehiclePrice + xtraCost;
}
else
{
vehiclePrice = vehiclePrice + 115 + xtraCost ;
}
}
//quoteText = quoteText + "Vehicle Hire for " + totalDays + " Days = $" + vehiclePrice + "\n" ;
if(document.getElementById("ChronoContact_quote_form").dropoff.value=='Christchurch')
{
dropoffPrice=0;
}
else if(document.getElementById("ChronoContact_quote_form").dropoff.value=='Auckland')
{
dropoffPrice=250;
}
else if(document.getElementById("ChronoContact_quote_form").dropoff.value=='Queenstown')
{
dropoffPrice=180;
}
else if(document.getElementById("ChronoContact_quote_form").dropoff.value=='Nelson')
{
dropoffPrice=180;
}
quoteText = quoteText + "Relocation Fee = $" + dropoffPrice + "\n";
if (document.getElementById("ChronoContact_quote_form").Bikes.value > 0)
{
/*Mountain Bikes*/
bikePrice = document.getElementById("ChronoContact_quote_form").Bikes.value*100;
quoteText = quoteText + "Hire " + document.getElementById("ChronoContact_quote_form").Bikes.value + " Bike(s) = $" + bikePrice + "\n" ;
}
if (document.getElementById("ChronoContact_quote_form").Kayaks.value > 0)
{
/*Kayaks*/
if(document.getElementById("ChronoContact_quote_form").Kayaks.value==2){
var perkayak=75;
}
else{
perkayak=100;
}
kayakPrice = document.getElementById("ChronoContact_quote_form").Kayaks.value*perkayak;
quoteText = quoteText + "Hire " + document.getElementById("ChronoContact_quote_form").Kayaks.value + " Kayak(s) = $" + kayakPrice + "\n" ;
}
if (document.getElementById("ChronoContact_quote_form").DVD.checked)
{
/*DVD Player*/
DVDPrice = 50;
quoteText = quoteText + "DVD Hire = $" + DVDPrice + "\n" ;
}
if (document.getElementById("ChronoContact_quote_form").Ski_Racks.checked)
{
/*Ski Rack*/
SkiRackPrice = 50;
quoteText = quoteText + "Ski Rack Hire = $" + SkiRackPrice + "\n" ;
}
if (document.getElementById("ChronoContact_quote_form").gps.checked)
{
/*GPS*/
gpsPrice = 50;
quoteText = quoteText + "G.P.S = $" + gpsPrice + "\n" ;
}
if (document.getElementById("ChronoContact_quote_form").portaloo.checked)
{
/*Portaloo*/
portalooPrice = 50;
quoteText = quoteText + "Portaloo = $" + portalooPrice + "\n" ;
}
if (document.getElementById("ChronoContact_quote_form").snowchains.checked)
{
/*Snowchains*/
snowchainsPrice = 50;
quoteText = quoteText + "Snowchains = $" + snowchainsPrice + "\n" ;
}
if (document.getElementById("ChronoContact_quote_form").boosterseat.checked)
{
/*Booster Seat*/
boosterseatPrice = 50;
quoteText = quoteText + "Booster Seat= $" + boosterseatPrice + "\n" ;
}
if (document.getElementById("ChronoContact_quote_form").babyseat.checked)
{
/*Baby Seat*/
babyseatPrice = 50;
quoteText = quoteText + "Babyseat = $" + babyseatPrice + "\n" ;
}
totalPrice = (vehiclePrice + bikePrice + kayakPrice + DVDPrice + SkiRackPrice + snowchainsPrice + portalooPrice + gpsPrice + dropoffPrice + babyseatPrice + boosterseatPrice);
var average_perday=totalPrice/totalDays;
var rounded_average_perday = roundNumber(average_perday,2);
quoteText = quoteText + "Total Days = " +totalDays + "\n";
quoteText = quoteText + "Average Cost Per Day = $" + rounded_average_perday + "\n";
if(daysOut>30){
var earlybird=totalPrice*0.1;
totalPrice=totalPrice * 0.9;
quoteText = quoteText + "Earlybird discount = $" + earlybird + "\n";
}
document.getElementById("ChronoContact_quote_form").Total.value = "$" + totalPrice + ".00 NZD" ;
quoteText = quoteText + "Total Amount for Hire = $" + totalPrice + "\n\n";
var deposit = roundNumber((totalPrice*.2),2);
quoteText = quoteText + "20% Deposit of $"+deposit+" will be charged on confirmation of booking";
document.getElementById("ChronoContact_quote_form").Quote_Result.value = quoteText ;
}
function printField()
{
var s = document.getElementById("ChronoContact_quote_form").Quote_Result.value ;
var regExp=/\n/gi ;
s = s.replace(regExp,'<br />') ;
pWin = window.open('','pWin','location=yes, menubar=yes, toolbar=yes') ;
pWin.document.open() ;
pWin.document.write('<html>')
pWin.document.write('<style type="text/css">*{font-family:arial, sans-serif;} img{display:block;}</style>')
pWin.document.write('<head></head><body>')
pWin.document.write('<img src="/images/quote_logo.jpg" />')
pWin.document.write(s) ;
pWin.document.write('</body></html>') ;
pWin.print() ;
pWin.document.close() ;
pWin.close() ;
}