user3055501
user3055501

Reputation: 315

Automatically Fill Out Text Input In HTML Form

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

Answers (2)

Filip Lukáč
Filip Lukáč

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

Digital Chris
Digital Chris

Reputation: 6202

You would put it in the value.

<input name="fieldname" value="<php $thedate ?>"/>

Upvotes: 2

Related Questions