user1901096
user1901096

Reputation: 247

Clone multiple input values into one input field

I'm trying to copy the input data of multiple fields into one big one, for date of birth.

day value + month value + year value = day value/month value/year value into one other field all together. I made variables of each field and then try to add them in the 'full' input field, but this doesn't work. What am I doing wrong?

Demo: http://jsfiddle.net/J2PHq/

$(function(){
    $('.copy').on('keyup blur', function(){
         $('.full').val(day + '/' + week + '/' + year);

        day = $(".day").val();
        week = $(".week").val();
        year = $(".year").val();
     }).blur();
});

Upvotes: 0

Views: 1077

Answers (2)

Pim Verlangen
Pim Verlangen

Reputation: 387

You need to declare the variables before you enter them in the .full field.

Working fiddle: here

$(function(){
    $('.copy').on('keyup blur', function(){        
        var day = $(".day").val();
        var week = $(".week").val();
        var year = $(".year").val(); 

        $('.full').val(day + '.' + week + '.' + year);

     }).blur();
});

Upvotes: 1

Adil Shaikh
Adil Shaikh

Reputation: 44740

Wrong execution order -

$(function(){
    $('.copy').on('keyup blur', function(){
        var day = $(".day").val();
        var week = $(".week").val();
        var year = $(".year").val();
        $('.full').val(day + '/' + week + '/' + year);
     }).blur();
});

Demo ---> http://jsfiddle.net/J2PHq/6/

Upvotes: 1

Related Questions