如何使单选按钮更改表单操作地址
我有一个表单,其中包含以下内容:
和一个单选按钮
<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。