Jump to content

Drop down date boxes


BigDaddy13

Recommended Posts

I would like to have 3 drop down boxes for a date.

First box = month, Second Box = Day, Third Box = Year

 

Is there a way that the number of days would be set according to the month

that was chosen? For example, if the month is June, a way to only show up to

30 days, instead of having 31 for every month?

 

 

BD

Link to comment
https://forums.phpfreaks.com/topic/163273-drop-down-date-boxes/
Share on other sites

This can be done with javascript without a page load, or you can do it with PHP by submitting the form (with javascript) every time a user chooses an item from a dropdown.  I would suggest using javascript.  And while you're doing that, you might as well use one of the nice date picker widgets that makes choosing a date really easy.  i.e. http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/datePicker.html

Link to comment
https://forums.phpfreaks.com/topic/163273-drop-down-date-boxes/#findComment-861414
Share on other sites

Thank you very much!

 

here is the html code

<input id="demo1" type="text" size="25"><a href="javascript:NewCal('demo1','MMddyyyy')"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a><br>
  <input type="submit" />

How do I make that input into the database?

 

I used this

Web: <input type="text" name="web" />

 

with regular text input.

 

Thanks again!

 

 

BD

 

 

Link to comment
https://forums.phpfreaks.com/topic/163273-drop-down-date-boxes/#findComment-861456
Share on other sites

I would start by making the date format something that php can easily convert, like yyyy-MM-dd.  Then you can use the strtotime() and date() functions to manipulate the date into whatever format you need to store it in the database.

 

<?php

if (isset($_POST['demo1']))
{
$date = $_POST['demo1'];

// strtotime returns FALSE if it cannot convert
// the string into a timestamp
if (($timestamp = strtotime($date)) !== FALSE)
{
	// Make sure you have already established 
	// a database connection at this point
	$query = "UPDATE table SET time = $timestamp WHERE id = 1";

	if ($result = mysql_query($query))
	{
		echo 'success';
	}
	else
	{
		echo 'fail';
	}
}
}

?>
<html>
<head>
<title>foo</title>
</head>
<body>
<form method="this_file.php" action="post">
	<input id="demo1" name="demo1" type="text" size="25">
	<a href="javascript:NewCal('demo1','yyyy-MM-dd')">
		<img src="cal.gif" width="16" height="16" border="0" alt="Pick a date" />
	</a>
	<br />
	<input type="submit" />
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/163273-drop-down-date-boxes/#findComment-861506
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.