ラジオボタンでフォームのアクションアドレスを変更する方法
次のフォームを取得しました
とラジオボタン
<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" />
フォーム アクションをregister_page4.phpではなくpayment.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 に移動します。