Solved

PHP/MySQL format date onBlur

Posted on 2011-02-22
4
502 Views
Last Modified: 2012-05-11
I have a form where a user will enter a follow-up date.  However, he doesn't want to have to enter the date in the yyyy/mm/dd format required by MySQL.  Is there a javascript that anyone knows of that will allow him to enter mm/dd/yyyy and, onBlur, have it correct it to yyyy/mm/dd format?  I can't seem to find such a script.  Thanks!
0
Comment
Question by:ssailer
  • 2
  • 2
4 Comments
 
LVL 20

Expert Comment

by:Proculopsis
ID: 34952759

Try something like this:

<html>

<head>
<title>http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q__26839012.html</title>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script src="http://filedb.experts-exchange.com/incoming/2011/02_w07/406422/DateExtension.js" type="text/javascript"></script>
<script>

$(function() {

  $("#format").click( function() {
    var date = new Date( $("#date").val() );
    var sqlDate = date.toString( "YYYY/MM/dd" );
    $("#date").val( sqlDate );
  });

});

</script>
</head>
<body>

<input id="date" value="22 feb 2011" />
<input id="format" type="button" value="Format">

</body>
</html>

Open in new window

0
 

Author Comment

by:ssailer
ID: 34952925
I'm actually looking for something that would do it onBlur, instead of onClick.  I'm just not good with javascript.  
0
 
LVL 20

Accepted Solution

by:
Proculopsis earned 250 total points
ID: 34953041

Just change the line:

  $("#format").click( function() {

to:

  $("#date").blur( function() {
0
 

Author Closing Comment

by:ssailer
ID: 34953134
Worked perfectly.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now