0

Hello,

I have this reservation form found on the main page of: http://www.avis.com.lb/
As you can see the current month "August" is selected as the default month and so is the year and day (the day is programmed to jump 2 days ahead for the renting of the car...)

However if you look closely (check the screenshot attached) you'll see that the month "August" is repeated twice and so is the year "2009", the current month is repeated twice. What I wanna do is remove the duplication and just auto select the current month without duplicating it.

I found this code: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_24229186.html
But it doesn't seem to work with my form, I donno why.

Here is the code of the script both javascript and a little bit of php

$date = strtotime("+2 day");
				$date2 = date('j',$date);
				 $date4 = strtotime("+5 day");
				$date3 = date('j',$date4);
				if($date3 == 1){
				$nextmonth = strtotime("+1 day");
				$monthid = date('m',$nextmonth);	
				}else{
				$nextmonth = strtotime("+0 day");
				$monthid = date('m',$nextmonth);	
				}
			if ($monthid==1){
				$year = date("Y") + 1;
			}else{
				$year = date("Y");
			}
          	//$pupday = date("j") - 12;
          	//$pupday = date("d") + 2;
          	//echo $pupday;
          	//$returnday = date("d") +5;
          	$month = date("F");
var xMonths = new Array( '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12' );

function getListValue( option_object  ){return option_object[ option_object.selectedIndex ].value;}
function setListValue( option_object, value  ){ option_object.selectedIndex = value;}
function addDays(myDate,days) {
    return new Date(myDate.getTime() + days*24*60*60*1000);
}
function init()
{
xToday = new Date();
yToday = addDays(new Date(),3);

xMonth = xToday.getMonth();
xDay = xToday.getDate()-1;
xYear = xToday.getYear()-2005; if (xYear < 2005) xYear=0;
yMonth = yToday.getMonth();
yDay = yToday.getDate()-1;
yYear = yToday.getYear()-2005; if (yYear < 2005) yYear=0;
  xF = document.forms['quickbooking'];
  setListValue( xF.ETAHour, 9 )
  setListValue( xF.ETAMonth, xMonth )
  setListValue( xF.ETADay, xDay )
  setListValue( xF.ETAYear, xYear )
  setListValue( xF.ETTHour, 9 )
  setListValue( xF.ETTMonth, yMonth )
  setListValue( xF.ETTDay, yDay )
  setListValue( xF.ETTYear, yYear )
}
<select class="formField" name="ETAMonth">
                <option value="<? echo $monthid; ?>"  selected="selected"><? echo $month; ?></option>
                <option 
                                value="01">January</option>
                <option 
                                value="02">February</option>
                <option value="03">March</option>
                <option 
                                value="04">April</option>
                <option value="05">May</option>
                <option 
                                value="06">June</option>
                <option value="07">July</option>
                <option 
                                value="08">August</option>
                <option value="09">September</option>
                <option 
                                value="10">October</option>
                <option value="11">November</option>
                <option 
                                value="12">December</option>
              </select>
              <select 
                                class="formField" name="ETAYear">
              <option value="<? echo $year; ?>" selected="selected"><? echo $year; ?></option>
              <option value="2008">2008</option>
              <option value="2009">2009</option>
              <option value="2010">2010</option>
            </select>

Help is very appreciated, thanks.

Attachments avisagust.jpg 25.39 KB
2
Contributors
1
Reply
3
Views
8 Years
Discussion Span
Last Post by essential
0

Hi,

you can try this with your form:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>www.daniweb.com</title>
<script type="text/javascript">
<!--
window.onload = ( function( monthid ) {
var monthid = ( monthid - 1 );
   return function() {
   var ids = 'quickbooking';
   var xF = ( document.forms ) ? document.forms[ ids ] : document.getElementById( ids );
  xF.ETAMonth.selectedIndex = monthid;
   /* 
   - You can apply this, along with your other option lists.

******************************** ~ Examples:
********************************
   xF.ETTDate.selectedIndex = dateVar; // or

   xF.ETTDate.options[ dateVar ].selected = true; 
*/
   } 
} )( <?php echo $monthid ?> );
// --> 
</script>
</head>
<body>
<form id="quickbooking" name="quickbooking" action="#">
<div>
Pick-up date: <b>?</b><br><select id="ETAMonth" name="ETAMonth" size="1">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select></div>
</form>
</body>
</html>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.