繁体   English   中英

如果选中复选框,则复制值

[英]Copy values if checkbox is checked

我需要添加 JavaScript 代码以在此表单上启用自动完成功能。 每当检查复选框时,代码应自动从运输名称和运输Z963AB0BBEA32F1F9D19D19D19AFB00D08BE14DZ中复制值,并将其计费到帐单名称中,并计费Z963AB0BBEA32F1F9D1F9D19D19D19AFB00D08BE14DZ。 如果未选中该复选框,则帐单名称和帐单 Zip 应为空白 go。 为什么我的代码不起作用?

我的 HTML 和 JS 代码如下:

 function billingFunction() { if (document.getElementById('same').checked) { var shipinfo = document.getElementById('shippingName', 'shippingZip').value; var billinfo = document.getElementById('billingName', 'billingZip').value; shipinfo = billinfo; } else { document.getElementById('billingName', 'billingZip').value = ''; } }
 <h1>JavaScript</h1> <p> Whenever the checkbox is checked, the code should automatically copy the values from Shipping Name and Shipping Zip into the Billing Name and Billing Zip. If the checkbox is unchecked, the Billing Name and Billing Zip should go blank.</p> <form> <fieldset> <legend>Shipping Information</legend> <label for="shippingName">Name:</label> <input type="text" name="shipName" id="shippingName" required><br/> <label for="shippingZip">Zip code:</label> <input type="text" name="shipZip" id="shippingZip" pattern="[0-9]{5}" required><br/> </fieldset> <input type="checkbox" id="same" name="same" onchange="billingFunction()" /> <label for="same">Is the Billing Information the Same?</label> <fieldset> <legend>Billing Information</legend> <label for="billingName">Name:</label> <input type="text" name="billName" id="billingName" required><br/> <label for="billingZip">Zip code:</label> <input type="text" name="billZip" id="billingZip" pattern="[0-9]{5}" required><br/> </fieldset> <input type="submit" value="Verify" /> </form>

function billingFunction() {
  if (document.getElementById('same').checked) {
    var shipinfo = document.getElementById('shippingName').value;
    var billinfo = document.getElementById('shippingZip').value;

    document.getElementById('billingName').value = shipinfo;
    document.getElementById('billingZip').value = billinfo;
  } else {
    document.getElementById('billingName').value = '';
    document.getElementById('billingZip').value = '';
  }
}

用这个

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM