Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
Convert a text type input field in a date type one with jQuery

Is there a way to convert a text type input field to a date type one with jQuery, so it will display to the user a date picker? I can add custom fields to a form created by a Wordpress plugin, but it doesn't support date nor datetime-local field types, and I need a such one.

<input name="adverts_eventDate" id="adverts_eventDate" type="text">
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You can easily change the type in jQuery:

$("#adverts_eventDate").attr("type","date");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name="adverts_eventDate" id="adverts_eventDate" type="text">

You can't change date format in HTML5 date:

Is there any way to change input type="date" format?

Since you can't change your date format in HTML5, I would recommend jQuery-UI.

Here's an example:

$( function() {
    $( "#adverts_eventDate" ).datepicker();
  } );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" rel="stylesheet"/>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<p>Date: <input name="adverts_eventDate" id="adverts_eventDate" type="text"></p>

about 4 years ago · Santiago Trujillo Report

0

convert a text type input field in a date type

You can use jquery's attr to change the type attribute from text to date.

$("#convert").click(function() {
  $("#adverts_eventDate").attr("type", "date")
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name="adverts_eventDate" id="adverts_eventDate" type="text">
<button id='convert'>to date</button>

about 4 years ago · Santiago Trujillo Report

0

You can use jquery-ui as follows

 <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
 <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js">       </script>
<input name="adverts_eventDate" id="adverts_eventDate" type="text">

and then

<script>
  $( function() {
    $( "#adverts_eventDate" ).datepicker();
  } );
  </script>
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!