hey all i'm new to this all and was wondering if anyone can help me solve a prob i'm havin with my project for a booking system.

i have a drop down menu with the day, one for months, and finaly year...
all the values are real time dates but i need to validate them so a date other than one in the future can't be selected to make a booking.

here is my code so far...

<body>

<?php 

$date = time();

$day = date('d', $date); 
$month = date('m', $date); 
$year = date('Y', $date);

$days_in_month = cal_days_in_month(0, $month, $year);

$current_month = date('F');
//echo $current_month;


?>
<script type="text/javascript">

Function year(id)
{
	var moy = document.getElementById(id).value;
	var month = "August"; //tried to hard code to check if worked - no luck
	
if(var moy <= month)
{
	document.writeln("awe");
	//echo "awe";
}
}
</script>

<form action="recive.php" method="post" name="CheckAvailability" target="_self" id="CheckAvailability">
    <table width="50%" border="0" cellpadding="6" align="center">
      <tr>
        <td><label for="daysOfMonth"></label>
          <div align="right">
            <select name="daysOfMonth" id="daysOfMonth" onchange="year(this.id)">
              <option><?php echo $day + 1; ?></option>
              <option>....</option>
              <?php 
				for($i = 1; $i <= $days_in_month; $i++)
				{
					echo "<option value=".$i.">".$i."</option>";
				}
			?>
            </select>
          </div></td>
        <td><label for="monthOfYear"></label>
          <div align="center">
            <select name="monthOfYear" id="monthOfYear">
              <option selected="selected"><?php echo $current_month; ?></option>
              <option>........</option>
              <option value="January">January</option>
              <option value="February">February</option>
              <option value="March">March</option>
              <option value="April">April</option>
              <option value="May">May</option>
              <option value="June">June</option>
              <option value="July">July</option>
              <option value="August">August</option>
              <option value="September">September</option>
              <option value="October">October</option>
              <option value="November">November</option>
              <option value="December">December</option>
            </select>
          </div></td>
        <td><label for="year"></label>
          <select name="year" id="year">
            <option selected="selected"><?php echo $year; ?></option>
            <option value="<?php echo $year + 1 ?>"><?php echo $year + 1 ?></option>
            <option value="<?php echo $year + 2 ?>"><?php echo $year + 2 ?></option>
          </select></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><label for="nights">
          <div align="right">Number of nights:</div>
        </label></td>
        <td><select name="nights" id="nights">
          <option value="1" selected="selected">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
          <option value="6">6</option>
          <option value="7">7</option>
          <option value="8">8</option>
          <option value="9">9</option>
          <option value="10">10</option>
          <option value="11">11</option>
          <option value="12">12</option>
          <option value="13">13</option>
          <option value="14">14</option>
          <option value="15">15</option>
          <option value="16">16</option>
          <option value="17">17</option>
          <option value="18">18</option>
          <option value="19">19</option>
          <option value="20">20</option>
          <option value="21">21</option>
        </select></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><label for="CheckAvailability"></label>
          <div align="center">
            <input type="submit" name="CheckAvailability2" id="CheckAvailability" value="Check Availability" />
          </div></td>
        <td>&nbsp;</td>
      </tr>
    </table>
  </form>

</body>

try:

<body>

<?php 

$date = time();

$day = date('d', $date); 
$month = date('m', $date); 
$year = date('Y', $date);

$days_in_month = cal_days_in_month(0, $month, $year);

$current_month = date('F');
//echo $current_month;


?>
<script type="text/javascript">

function isValidDate()
{
	var now = new Date();
	
	//advance one day
	now.setDate( now.getDate() + 1 );

	var Day=document.getElementById('daysOfMonth');
	var Month=document.getElementById('monthOfYear');
	var Year=document.getElementById('year');

	var selectedDate= new Date(Month + " " + Day + " " + Year);
	if(now < selectedDate)
	{
		alert("You may select only future dates");
	}
}
</script>

<form action="recive.php" method="post" name="CheckAvailability" target="_self" id="CheckAvailability">
    <table width="50%" border="0" cellpadding="6" align="center">
      <tr>
        <td><label for="daysOfMonth"></label>
          <div align="right">
            <select name="daysOfMonth" id="daysOfMonth" onchange="isValidDate()">
              <option><?php echo $day + 1; ?></option>
              <?php 
				for($i = 1; $i <= $days_in_month; $i++)
				{
					echo "<option value=".$i.">".$i."</option>";
				}
			?>
            </select>
          </div></td>
        <td><label for="monthOfYear"></label>
          <div align="center">
            <select name="monthOfYear" id="monthOfYear" onchange="isValidDate()">
              <option selected="selected"><?php echo $current_month; ?></option>
              <option value="January">January</option>
              <option value="February">February</option>
              <option value="March">March</option>
              <option value="April">April</option>
              <option value="May">May</option>
              <option value="June">June</option>
              <option value="July">July</option>
              <option value="August">August</option>
              <option value="September">September</option>
              <option value="October">October</option>
              <option value="November">November</option>
              <option value="December">December</option>
            </select>
          </div></td>
        <td><label for="year"></label>
          <select name="year" id="year" onchange="isValidDate()">
            <option selected="selected"><?php echo $year; ?></option>
            <option value="<?php echo $year + 1 ?>"><?php echo $year + 1 ?></option>
            <option value="<?php echo $year + 2 ?>"><?php echo $year + 2 ?></option>
          </select></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><label for="nights">
          <div align="right">Number of nights:</div>
        </label></td>
        <td><select name="nights" id="nights">
          <option value="1" selected="selected">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
          <option value="6">6</option>
          <option value="7">7</option>
          <option value="8">8</option>
          <option value="9">9</option>
          <option value="10">10</option>
          <option value="11">11</option>
          <option value="12">12</option>
          <option value="13">13</option>
          <option value="14">14</option>
          <option value="15">15</option>
          <option value="16">16</option>
          <option value="17">17</option>
          <option value="18">18</option>
          <option value="19">19</option>
          <option value="20">20</option>
          <option value="21">21</option>
        </select></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><label for="CheckAvailability"></label>
          <div align="center">
            <input type="submit" name="CheckAvailability2" id="CheckAvailability" value="Check Availability" />
          </div></td>
        <td>&nbsp;</td>
      </tr>
    </table>
  </form>

</body>

why this thread is in the Introduction section? haha :))

hey sorry new to this site... didn't know was introduction section - hahaha

well i tried the code but still not working... think it could be this code snippit

line 31... var selectedDate= new Date(Month + " " + Day + " " + Year);

seems as though it won't go into the if statment.

a little stuck.. any help??

Try making the following changes:

...
var Day=document.getElementById('daysOfMonth');
var Month=document.getElementById('monthOfYear');
var Year=document.getElementById('year');

var str = Month + " " + Day + " " + Year;
alert(str);
var selectedDate= new Date(str);
...

I was expecting str to be SIMILAR to:
August 28 2010

What does the code above alert() for you?

[object HTMLSelectElement] [object HTMLSelectElement] [object HTMLSelectElement]

that seems to be the alert message... however still not going into if()

var selectedDate = new Date();
selectedDate.setFullYear(Year, Month, Day);

tried this too but nothing seems to be working to get the onchange function to do what it needs to do.

My apologies for the oversight. In my original code, I forgot to add ".value" at the end of the statements that retrieve the Month, Day, and Year. It should have been:

var Day=document.getElementById('daysOfMonth').value;
var Month=document.getElementById('monthOfYear').value;
var Year=document.getElementById('year').value;

got it... thanks a lot man.

helped me out there. awe

You are welcome. Please be sure to mark the thread as solved.

Regards,
Hielo

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.