Reputation: 315
I'm trying to code a form which has an input (of type text) that will be automatically filled out with today's date when the user views the form. I already know how to get today's date in PHP, but I don't know how to make it automatically be typed into the form. This is different than a placeholder because placeholders disappear when the text input is clicked on. I want the date to be as if the user typed it into the form, but done automatically. How would I code this using HTML/CSS?
Upvotes: 0
Views: 5372
Reputation: 100
Try something like this give your input id
<input id="date" name="fieldname"/>
Then use jquery to update value
$(doument).ready(function(){
$('#date').val(new Date());
});
Or with php
<input id="date" name="fieldname" value="<?php echo date("Y-m-d H:i:s"); ?>"/>
Upvotes: 0
Reputation: 6202
You would put it in the value.
<input name="fieldname" value="<php $thedate ?>"/>
Upvotes: 2