Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

219
Visualizações
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">
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

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>

over 4 years ago · Santiago Trujillo Relatório

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>

over 4 years ago · Santiago Trujillo Relatório

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>
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda