I’m unable to find a previous date by inputing a given date by a user using html and javascript. Can you please help me out
تبليغيرجى شرح بإيجاز لمإذا تشعر أنك ينبغي الإبلاغ عن هذا السؤال.
‘This is the HTML Code’
<form>
<div class=”input-field”>
<label>Choose Date</label>
<input type=”date” id=”date” onchange=”myDate();” required>
</div>
<div class=”input-fields”>
<label>Previous Date</label>
<input type=”date” id=”previous” readonly>
</div>
</form>
‘This is the Javascript Code’
<script>
function myDate()
{
const currDate = document.getElementById(“date”);
const date = new Date(currDate)
if (typeof date === ‘object’ && date !== null && ‘getDate’ in date) {
console.log(“The data type is”, typeof date)
console.log(date.getDate())}
else {
console.log(“Invalid Date Object”)
}
date.setDate(date.getDate()-1);
const previous = document.write(date);
document.getElementById(“previous”).value = previous;
}
</script>
I’m trying to get previous date by using the myDate Function in Javascript and i was getting an error getDate is not a function then i tried to make getDate as function and now its showing the same error. I’m not able to make a getDate as function or getting previous date value
أضف إجابة