Link to home
Start Free TrialLog in
Avatar of Whing Dela Cruz
Whing Dela CruzFlag for Anguilla

asked on

Today Date

Hi experts, I'm having a problem with the code below where the myDate value is not telling the correct date of the day. On the other hand, the alert message is showing correct answers. Which part of the code is wrong? any help, please!

 
<!DOCTYPE html>
<html>
<body>

Today: <input type="date" id="myDate">

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
    document.getElementById("myDate").valueAsDate = new Date();
    alert(new Date);
}
</script>

</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Whing Dela Cruz

ASKER

Thank you, so much both of you guys!