Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP/MySQL format date onBlur

Posted on 2011-02-22
4
Medium Priority
?
515 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 1000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
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 …
Suggested Courses

971 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