0

我想让我的账单字段自动匹配我的运输字段。我可以使它与文本值一起使用,但我不能自动填充无线电按钮。我正在使用此代码: http: //jsfiddle.net/aDNH7/我想将其保留在 Javascript 中。

<script>
function FillBilling(f) {
  if(f.billingtoo.checked == true) {
    f.billingname.value = f.shippingname.value;
    f.billingcity.value = f.shippingcity.value;
  }
    if(f.billingtoo.checked == false) {
    f.billingname.value = '';
    f.billingcity.value = '';
  }
}
</script>
<td bgcolor="eeeeee">
<b>Mailing Address</b>
<br><br>
<form>
Name:
<input type="text" name="shippingname">
<br>
City:
<input type="text" name="shippingcity">


/> 检查
/> 储蓄

<br>
<input type="checkbox" onclick="FillBilling(this.form)" name="billingtoo">
<em>Check this box if Billing Address and Mailing Address are the same.</em>
<p>
<b>Billing Address</b>
<br><br>
Name:
<input type="text" name="billingname">
<br>
City:
<input type="text" name="billingcity">


/> 检查
/> 储蓄

​</p>
BUT, I want to add this to the form for both the BILLING and SHIPPING. And then I want the SHIPPING one to match up with the BILLING one if I check the box.

<!-- <td colspan="2"><p>
  <label>
    <input type="radio" name="acct" value="checking" id="acct_0" <?php if ($user_info['acct'] == "checking"){ echo "checked='checked'"; }?>/>
    Checking</label>
  <br />
  <label>
    <input type="radio" name="acct" value="savings" id="acct_1" <?php if ($user_info['acct'] == "savings"){ echo "checked='checked'"; }?>/>
    Savings</label>
  <br />
</p>
</td>-->
4

1 回答 1

0

Javascript:

document.getElementById("acct_0").setAttribute("checked", "checked");

Jsfiddle在这里

于 2012-12-12T21:53:28.490 回答