Solved

PHP/MySQL format date onBlur

Posted on 2011-02-22
4
508 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

631 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