0

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)"
3
  • The line in your else doesn't make sense. What is .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. Commented Jan 10, 2013 at 11:05
  • 1
    @Amberlamps: I vote up a question if they help a bit but do not help to solving the problem, I accept an answer if an answer help directly with solving my question! Commented Jan 10, 2013 at 11:09
  • @MarcellFülöp: I actually did not need the If statement at all as the values would be the same all the time Commented Jan 10, 2013 at 11:10

1 Answer 1

1

I think you need not check the condition since in all cases the values should be same. So you can change that condition and the statement in else part. that may solve the problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.