-4

送信ボタンがクリックされたときに、フォームから生まれた年の代わりに年齢をサーバーに送信したい。それを達成する最も簡単な方法は何ですか?

<form action="process.php">
    <input type="text" name="yearBorn">
    <input type="hidden" name="Age">
    <input type="submit" >
</form>
4

3 に答える 3

1

"からのイベントのキャプチャに基づいていない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
        }
    });
});
于 2013-07-31T21:18:06.257 に答える
0

提案されたサーバー側の計算は問題を解決しますか/決定的な JavaScript ソリューションが必要ですか?

$age = $date("Y") - $_POST[yearBorn];

トリックを行います。

于 2013-07-31T19:39:34.350 に答える