Load date in input

2

I'm making a form and to insert the date and send it I have no problem. The problem comes when I try to manually enter a date from js, it does not load.

I enclose the input code:

<input class="form-control datetimepicker" type="date" id="fecha_nacimiento" name="fecha_nacimiento"/>

And I have attached the JS code:

$('#fecha_nacimiento').val(fecha_nacimiento);

Being date of birth a style value: 01/01/1990.

Any ideas? Thanks in advance.

    
asked by Sergio Araque 21.06.2018 в 12:08
source

1 answer

3

You have to change to the English format of the input.

$( document ).ready(function() {          $('#fecha_nacimiento').val('2013-12-31');
                                
});
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <title>Test</title>
</head>
<body>
  <input class="form-control datetimepicker" type="date" id="fecha_nacimiento" name="fecha_nacimiento"/>
</body>
</html>

You can look here too Setting format and value in date

    
answered by 21.06.2018 / 12:39
source