2013-06-24 109 views
0

在我的MVC項目中,當客戶創建一個賬戶時,他們會提示輸入發票地址和送貨地址。用複選框自動更新字段

我想要一個複選框,位於發票地址下方,它將使用相同的發票地址詳細信息更新送貨地址,而不是必須輸入相同的地址兩次。

不知道如何做到這一點,任何幫助,將不勝感激)複選框的一個例子是

<div class="checkbox">@Html.CheckBoxFor(m => signup.SameAddress)</div> 
<div class="label">@Html.LabelFor(m => signup.SameAddress, T(Use same address as billing"))</div> 

到目前爲止,我的代碼如下所示(下圖)。他們必須輸入兩次相同的細節。

<article class="addresses form"> 
<fieldset> 
    <div class="span5"> 
    <h2>@T("Invoice Address")</h2> 

    <table class="table-bordered table-striped table"> 
     <colgroup> 
      <col id="Col1" /> 
      <col id="Col2" /> 
     </colgroup> 
     <thead> 
      <tr> 
       <th scope="col">@T("Name")</th> 
       <td>@invoiceAddress.Name.Value</td> 
      </tr> 
      <tr> 
       <th scope="col">@T("AddressLine1")</th> 
       <td>@invoiceAddress.AddressLine1.Value<</td> 
      </tr>    
     </thead> 
    </table> 
    </div> 

    //insert checkbox here 

    <div class="span5"> 
    <h2>@T("Billing Address")</h2> 
    <table class="table-bordered table-striped table"> 
     <colgroup> 
      <col id="Col1" /> 
      <col id="Col2" /> 
     </colgroup> 
     <thead> 
      <tr> 
       <th scope="col">@T("Name")</th> 
       <td>@shippingAddress.Name.Value</td> 
      </tr> 
      <tr> 
       <th scope="col">@T("AddressLine1")</th> 
       <td>@shippingAddress.AddressLine1.Value<</td> 
      </tr>    
     </thead> 

    </table> 
    </div> 
</fieldset> 
</article> 

我想使用JQuery或JS來自動更新送貨地址到發票給定的地址。

感謝您的任何答覆......

回答

1

你需要的東西,以確定你的專欄中,我使用的輸入標籤在這裏與IDS,我可以選擇的。

<input type="checkbox" id="test3"/> 
<label for="test1">Invoice address</label><input id="test1" type="text"/> 
<label for="test2">Shipping address</label><input id="test2" type="text"/> 


$("#test1").on("change", function() { 
    if ($("#test3").is(":checked")) 
     $("#test2").val($(this).val()) ; 
}); 
+0

好的不錯謝謝你的幫助Erik – John