如何使单选按钮更改表单操作地址
我得到了一个具有以下内容的表格
和一个单选按钮
<b>Would you like to to make payment ? <input type="radio" name="choice" value="yes">Yes <input type="radio" name="choice" value="no" checked>No</b>'
如果用户选择是no
(默认选中),表单action
仍然是register_page4.php
但如果用户选择yes
并按下提交按钮:
<input id="btnSubmit" type="submit" value="Next" />
我希望表单操作是payment.php而不是register_page4.php,我该如何实现。
我进行了更改,这就是我输入的内容
<html>
<head>
</head>
<body>
<form name="form1" method="post" action="register_page4.php">
Would you like to make an appointment for collection ?
<input type="radio" name="collection" value="yes">Yes
<input type="radio" name="collection" value="no" checked>No
<input id="btnSubmit" type="submit" value="Next" />
</form>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
jQuery(document).ready(function($) {
var form = $('form[name="form1"]'),
radio = $('input[name="choice"]'),
choice = '';
radio.change(function(e) {
choice = this.value;
if (choice === 'yes') {
form.attr('action', 'payment.php');
} else {
form.attr('action', 'register_page4.php');
}
});
});
</script>
</body>
</html>
但结果仍然是 register_page4.php 即使我点击单选按钮是,我尝试点击两者,两者仍然去 register_page4.php