Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a asp.net form, which is using two Person usercontrols, one named 'BillingInfo' and one named 'ShippingInfo'. The person usercontrol has a "Address" input field that has the class set to "address1". On my order page, how can I assign the value of one Address field into the other using javascript? The dynamic IDs are throwing me off. Each control is inside of a div, titled "ShippingContactInfo" and "BillingContactInfo" respectively. The function is firing, and when executing, the objects are being populated, but for some reason the value assignment is not doing anything on the page.

I have tried:

  function copyBillingAddress(f) {
    if (copyBillingCheckBox.checked == true) {
        var addrCopyFromVal = $('#ShippingContactInfo .address1').value;
        var addrCopyTo = $('#BillingContactInfo .address1');
        addrCopyTo.val(addrCopyFromVal.val());
       }
}
share|improve this question

2 Answers 2

up vote 3 down vote accepted

Try this. It should be .val() not .value on a jquery object.

You can use the val() as getter as well as val(somevalue) as setter as you are using already.

    var addrCopyFromVal = $('#ShippingContactInfo .address1').val(); //<-- Here
    var addrCopyTo = $('#BillingContactInfo .address1');
    addrCopyTo.val(addrCopyFromVal); // <-- And here

or just simply write:

$('#BillingContactInfo .address1').val($('#ShippingContactInfo .address1').val());

See .val()

share|improve this answer
1  
I see my mistake now . Thanks! –  steve Jun 11 '13 at 23:28

you can use through change event of copyBillingCheckBox

$("#copyBillingCheckBox").change(function(){

        if(this.checked)
        {
           $('#BillingContactInfo .address1').val($('#ShippingContactInfo .address1').val());
        }
        else{
             $('#BillingContactInfo .address1').val("");
        }

    });
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.