Solved

PHP/MySQL format date onBlur

Posted on 2011-02-22
4
506 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

739 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