copy and concatenate values of multiple input boxes in a form to one input field

前端 未结 2 1711
一向
一向 2020-12-15 14:25

copy/duplicate and concatenate values of multiple input boxes to one

I have input fields for street, city, state and zip and the fifth one that says complete address

相关标签:
2条回答
  • 2020-12-15 14:55

    Use the + for Javascript concatenation:

    $('#latlongaddress').val($('#street').val() + ' ' +
                             $('#city').val() + ', ' +
                             $('#state').val() + ' ' +
                             $('#zip').val() );
    

    See the jsFiddle.

    0 讨论(0)
  • 2020-12-15 15:02

    Just for fun:

    $('#latlongaddress').val( $('#street,#city,#state,#zip').map(function(){
        return $(this).val();
    }).get().join(' ') );
    

    eykanal's answer is better because it will run quicker and is easier to understand. Only actually use this for something like .val($('input')...

    0 讨论(0)
提交回复
热议问题