送信ボタンがクリックされたときに、フォームから生まれた年の代わりに年齢をサーバーに送信したい。それを達成する最も簡単な方法は何ですか?
<form action="process.php">
<input type="text" name="yearBorn">
<input type="hidden" name="Age">
<input type="submit" >
</form>
送信ボタンがクリックされたときに、フォームから生まれた年の代わりに年齢をサーバーに送信したい。それを達成する最も簡単な方法は何ですか?
<form action="process.php">
<input type="text" name="yearBorn">
<input type="hidden" name="Age">
<input type="submit" >
</form>
"からのイベントのキャプチャに基づいていないJavascript/ jQueryyearBorn
ソリューション"? これが私が思いつくことができる唯一の解決策です:
$('form').submit(function (e) {
// Prevents the form from being submitted
e.preventDefault();
// Find outs the age
var age = new Date().getFullYear() - $('input[name="yearBorn"]').val();
// Submits the form through AJAX, so in server-side you can get the age
$.ajax({
type: 'POST',
url: 'process.php',
data: {'age': age},
success: function (data) {
// If successful, do your stuff here
}
});
});
提案されたサーバー側の計算は問題を解決しますか/決定的な JavaScript ソリューションが必要ですか?
$age = $date("Y") - $_POST[yearBorn];
トリックを行います。