PHP Programming > Beginners - Learning PHP

php datepicker problem

(1/1)

calazarpolate:
i am a newbie. Tired of searching through net if someone could help me. How to insert the date value through js datepicker showing the user in "dd-mm-yyyy" format.

date.html
______________________________________________________
<html>
<head>
      <link type="text/css" href="css/ui-lightness/jquery-ui-1.8.21.custom.css" rel="stylesheet" />
      <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
      <script type="text/javascript" src="js/jquery-ui-1.8.21.custom.min.js"></script>
  <script type="text/javascript">
  $(document).ready(function(){
    $("#datepicker").datepicker({
 onSelect: function(dateText, inst) {
 alert(dateText);
 document.getElementById('thedate').value=dateText; }
}
);
  });
  </script>
</head>
<body style="font-size:62.5%;">
<div type="text" id="datepicker"></div>
<form method=post action="save.php">
<input type='text' id='thedate' name='thedate' />
<input type='submit' value="save">
</form>
</body>
</html>

save.php
_____________________________________________________________

      <?php
$host="localhost";
$username="root";
$password="";
$databasename="saving";
$conn = mysql_connect($host,$username,$password) or die("cannot connect database");

mysql_select_db($databasename,$conn) or die ("cannot find database");

$thedate = stripslashes(trim ($_POST['thedate']));
$select_record ="select * from only where thedate ='".$thedate."'";

$select_query = mysql_query($select_record) or die (mysql_error());
if (mysql_numrows($select_query)==0)
{
$thedate = stripslashes(trim($_POST['thedate']));
$add_new = "insert into only (thedate) values ('$thedate')";
$add_query = mysql_query($add_new) or die (mysql_error());
if ($add_query)
{
echo "New Record Added !!";
}
}
else
echo "Not Added";
?> 

Smokey PHP:
Found the answer on the jQuery UI datepicker documentation page (modify their example below to suit your needs).


--- Quote ---Initialize a datepicker with the dateFormat option specified.

    $( ".selector" ).datepicker({ dateFormat: "yy-mm-dd" });

Get or set the dateFormat option, after init.

    //getter
    var dateFormat = $( ".selector" ).datepicker( "option", "dateFormat" );
    //setter
    $( ".selector" ).datepicker( "option", "dateFormat", "yy-mm-dd" );


--- End quote ---

Source: http://jqueryui.com/demos/datepicker/

calazarpolate:
Thanx for the reply. but if you could help me out a little bit more. i'm new to javascript.

calazarpolate:
okay got it....thanx a lot.

Navigation

[0] Message Index

Go to full version