Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I can't figure out how to populate date from one textbox to another

This is my code:

$(function () {
    $("#newDepBirthDate").datepicker();
    $("#newDepBecameDep").datepicker();
    $("#newDepBirthDate").focusout(function(){
        $("#newDepBecameDep").val($("#newDepBirthDate").val());
        });
});


This does not work because when leaving a textbox the value is not there.
Posted
Comments
Maarten Kools 29-Jan-14 17:26pm    
You're using the Datepicker from jQueryUI I assume? Use the onClose[^] method
Code_Observer 29-Jan-14 18:56pm    
Thank you so much this actually worked. That was perfect my complete code is this now:


$(function () {
$("#newDepBirthDate").datepicker({
onClose: function() {
$("#newDepBecameDep").val($("#newDepBirthDate").val());
}
});
$("#newDepBecameDep").datepicker();
});

1 solution

After you selecting a date from the date-picker the input box does not get the focus, so when clicking on the other input box there is no focusout event on the first input...

Try this:
JavaScript
$(function () {
    $("#newDepBirthDate").datepicker();
    $("#newDepBecameDep").datepicker();
    $("#newDepBecameDep").focusin(function () {
        $("#newDepBecameDep").val($("#newDepBirthDate").val());
    });
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900