html input date input type

BR
BR used Ask the Experts™
on
Dear Experts,

I use below input type however I need to dynamicly use it.
I want to default value of input is today's date with the same format 2018-10-03.
How can I do this?

<input type="date" id="start" name="trip"   value="2018-07-22"  min="2018-01-01" max="2018-12-31" />
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You use JavaScript
<script>
document.addEventListener('load', function() {
  document.getElementById('start').value = dmy();
});
function dmy()
{
	var date = new Date();
	return date.getFullYear() + '-' + ('00' + (date.getMonth()+1)).substr(-2) + '-' + ('00' +(date.getDate()+1)).substr(-2);
}
</script>

Open in new window

BRDigital Marketing

Author

Commented:
Dear Julian Hansen,
this code is not working? something is missin?
thank you
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
That does not help me.

You need to tell me how it is not working

1. Is there an error - if so what
2. Is the code not doing what you want it to - if so how did you implement the code - show me the code so I can see what you have done.

General advice when responding on these forums: give enough information for an expert to be able to respond.

If you just say it is not working I cannot possibly know how you have implemented the solution so I cannot help you.

The code I posted I put in this sample and it appears to be working as expected.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You cannot change the default display format of the <input> control currently - you would need to use a custom component for that.
BRDigital Marketing

Author

Commented:
Dear Julian Hansen, your Sample code is working.
thank you, it solves my problem.

Also PHP helps too. Thank you

value="<?php echo date("d/m/Y");?>"

Open in new window

Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You are welcome.

Remember if you want a PHP solution - add it to the Topic Areas so we know that is an option.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial