[英]Javascript for checkbox to copy billing text boxes over to shipping text boxes
到目前为止,我一直在尝试找到一种很好的方法,当用户选中复选框说明其帐单信息与他们的送货信息相同时,在文本框中获取帐单信息并将其复制到“送货信息”文本框中。
到目前为止,我有以下代码:
function InputInformation(n) {
if(n.checked === false) { return; }
document.subscribe.billingfname.value = document.subscribe.shippingfname.value;
document.subscribe.billinglname.value = document.subscribe.shippinglname.value;
document.subscribe.billingaddress.value = document.subscribe.shippingaddress.value;
document.subscribe.billingcity.value = document.subscribe.shippingcity.value;
document.subscribe.billingstate.value = document.subscribe.shippingstate.value;
document.subscribe.billingzip.value = document.subscribe.shippingzip.value;
document.subscribe.billingphone.value = document.subscribe.shippingphone.value;
}
return InputInformation;
我无法使它工作。 我不确定自己在做什么错。 任何帮助将是巨大的!
javascript遵循以下形式:
<form class="wrap" name="subscribe">
<tr class="left-container">
<h2>Billing Information:</h2>
<td>
<span class="labels">First name: </span>
<input type="text" name="billingfname">
</td>
<br>
<td>
<span class="labels"> Last name: </span>
<input type="text" name="billinglname">
</td>
<br>
<td>
<span class="labels">Address: </span>
<input type="text" name="billingaddress" style="width: 200px">
</td>
<br>
<td>
<span class="labels">City: </span>
<input type="text" name="billingcity">
</td>
<br>
<td>
<span class="labels">State: </span>
<input type="text" name="billingstate">
</td>
<br>
<td>
<span class="labels">Zip Code: </span>
<input type="text" name="billingzip" style="width: 80px">
</td>
<br>
<td>
<span class="labels">Telephone </span>
<input type="text" name="billingphone" style="width: 80px">
</td>
</tr>
<tr class="right-container">
<h2>Shipping Information:</h2>
<td>
<input class="shipping" type="checkbox" onclick="InputInformation(this)">Check if Shipping is the same as Billing
</td>
<br>
<td>
<span class="labels">First name: </span>
<input type="text" name="shippingfname">
</td>
<br>
<td>
<span class="labels"> Last name: </span>
<input type="text" name="shippinglname">
</td>
<br>
<td>
<span class="labels">Address: </span>
<input type="text" name="shippingaddress" style="width: 200px">
</td>
<br>
<td>
<span class="labels">City: </span>
<input type="text" name="shippingcity">
</td>
<br>
<td>
<span class="labels">State: </span>
<input type="text" name="shippingstate">
</td>
<br>
<td>
<span class="labels">Zip Code: </span>
<input type="text" name="shippingzip" style="width: 80px">
</td>
<br>
<td>
<span class="labels">Telephone </span>
<input type="text" name="shippingphone" style="width: 80px">
</td>
</tr>
</form>
我猜您正在尝试将运输方式复制到代码段中的帐单上,这应该是另一种方式。
检查下面的代码段。
function InputInformation(n) { if(n.checked === false) { alert('sdf');return false; } document.subscribe.shippingfname.value = document.subscribe.billingfname.value; document.subscribe.shippinglname.value = document.subscribe.billinglname.value; document.subscribe.shippingaddress.value = document.subscribe.billingaddress.value; document.subscribe.shippingcity.value = document.subscribe.billingcity.value; document.subscribe.shippingstate.value = document.subscribe.billingstate.value; document.subscribe.shippingzip.value = document.subscribe.billingzip.value; document.subscribe.shippingphone.value = document.subscribe.billingphone.value; }
<form class="wrap" name="subscribe"> <tr class="left-container"> <h2>Billing Information:</h2> <td> <span class="labels">First name: </span> <input type="text" name="billingfname"> </td> <br> <td> <span class="labels"> Last name: </span> <input type="text" name="billinglname"> </td> <br> <td> <span class="labels">Address: </span> <input type="text" name="billingaddress" style="width: 200px"> </td> <br> <td> <span class="labels">City: </span> <input type="text" name="billingcity"> </td> <br> <td> <span class="labels">State: </span> <input type="text" name="billingstate"> </td> <br> <td> <span class="labels">Zip Code: </span> <input type="text" name="billingzip" style="width: 80px"> </td> <br> <td> <span class="labels">Telephone </span> <input type="text" name="billingphone" style="width: 80px"> </td> </tr> <tr class="right-container"> <h2>Shipping Information:</h2> <td> <input class="shipping" type="checkbox" onchange="InputInformation(this)">Check if Shipping is the same as Billing </td> <br> <td> <span class="labels">First name: </span> <input type="text" name="shippingfname"> </td> <br> <td> <span class="labels"> Last name: </span> <input type="text" name="shippinglname"> </td> <br> <td> <span class="labels">Address: </span> <input type="text" name="shippingaddress" style="width: 200px"> </td> <br> <td> <span class="labels">City: </span> <input type="text" name="shippingcity"> </td> <br> <td> <span class="labels">State: </span> <input type="text" name="shippingstate"> </td> <br> <td> <span class="labels">Zip Code: </span> <input type="text" name="shippingzip" style="width: 80px"> </td> <br> <td> <span class="labels">Telephone </span> <input type="text" name="shippingphone" style="width: 80px"> </td> </tr> </form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.