I have an HTML page and I am trying to write a function in javascript so that if a particular date field is blank, another field on the page will also be blank. but if the field is populated the other field on the page will also be populated with the same date.
I can get this working so if the first field is populated the second is also populated with the same date. but when you remove the date from the first field the second field remains populated.
So my question is how do i get this working so that the second field will be blank if the first field is blank
Function:
function checkIfDatePresent(date) {
var theDate = date;
if (theDate.value != "") {
document.getElementById("sentDate").value = theDate.value;
} else {
document.getElementById("sentDate").style.clear;
}
}
Calling using 'onchange' event:
onchange="javascript:checkIfDatePresent(this)"
.style.clear? Probably you don't need the if/else here. Just do what you do in the if clause and get rid of the if/else.