How to leave current date in text field

2

I'd like to populate my text field with data atual , where the mask I have, when the user types lets it set like this: xx/xx/xxxx . How to do in JS or PHP?

    
asked by anonymous 05.11.2014 / 12:44

2 answers

3

You can do two ways, get the current date of your server, with PHP, ASP or Java, or pick up the current date of the client via JS

From the server, with PHP:

<input id='data' type='text' value='<?php echo date("d/m/Y"); ?>'>

From the client, with JS:

function pegarDataAtual(){
   data = new Date();
   document.getElementById('data').value = data.getDay()+'/'+data.getMonth()+'/'+data.getFullYear();
}

Now inside the onload of the body you can call this function. Simple like this:)

I recommend using server side, it is better to trust the date that is on your server than the date that comes from the client

If you want to just leave it in the mask, instead of putting it in value of input , you can put it in the placeholder

    
05.11.2014 / 12:57
1

This issue can be resolved at this link. If it is in Jquery of course, you did not specify in which language.

Specify date format Jquery

Example:

$('#yourInputBoxHere').mask("99/99/9999", {placeholder: 'MM/DD/YYYY' });

Or in html5?

Format Mask Date Html5

Example:

<input type=date step=7 min=2014-09-08>
<input type=time min=9:00 max=17:00 step=900>
<input type=week step=2 min=2014-W30>
    
05.11.2014 / 12:58