我想根据选中的复选框将隐藏的输入写入表单。在我的示例中,我没有收到错误,但它仍然不会通过隐藏字段-(已编辑)
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<div id="test"></div>
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="youremail@mail.com">
<input type="hidden" name="currency_code" value="US">
<input type="checkbox" id="chkbox1" name="camp1" value="a">
<input type="checkbox" id="chkbox2" name="camp2" value="b">
<input type="submit" value="PayPal">
</form>
<script type="text/javascript">
var element = document.getElementById('test');
if(element != null && element.checked) {
var newElement = document.createElement('input');
newElement.type = "hidden";
newElement.name = "item_name_1";
newElement.value = "MyItem #1";
document.getElementById('chkbox1').appendChild(newElement);
var newElement2 = document.createElement('input');
newElement2.type = "hidden";
newElement2.name = "amount_1";
newElement2.value = "7.00";
document.getElementById('test').appendChild(newElement2);
}
理论上这应该有效,但它让我很难过。如果有人可以提供一些建议,将不胜感激。