0

javascript 関数から返された変数をフォームで送信する必要があります。

<form name="RegForm"  method="post" action="/validate_accountinfo.php" onsubmit="send()">
</form>


function send()
{
   var number = 5;
   return number;
}

validate_accountinfo.php で、関数の値を返したいと思います。これを行う方法?

4

4 に答える 4

1

フォームに隠しフィールドを配置し、JavaScript 関数でその値を設定します。

隠しフィールド:

<input type="hidden" id="hdnNumber">

JavaScript:

function send(){
    var number = 5;
    document.getElementById("hdnNumber").value = number;
}
于 2013-03-11T19:58:11.460 に答える
0

フォームにを追加し、<input hidden id="thevalue" name="thevalue" />javascriptを使用してその値を設定してから、フォームを送信します。

<form id="RegForm" name="RegForm"  method="post" action="/validate_accountinfo.php" onsubmit="send()">
    <input hidden id="thevalue" name="thevalue" />
</form>

<script type="text/javascript">
function send()
{
   var number = 5;
   return number;
}
document.getElementById('thevalue').value = send();
document.getElementById('RegForm').submit();
</script>
于 2013-03-11T19:57:06.293 に答える
0

を作成し<input type="hidden" id="field" />、jQueryでその値を更新します。

$("#field").attr({value: YourValue });
于 2013-03-11T19:57:25.287 に答える
0

非表示の入力を追加し、送信する前に入力します。必ず属性を指定してくださいname=

<form name="RegForm"  method="post" action="/validate_accountinfo.php" onsubmit="send()">
    <input type="hidden" name="myvalue"/>
</form>


function send()
{
    var number = 5;

    // jQuery
    $('input[name=myvalue]').val( number )

    return true;
}
于 2013-03-11T19:58:11.537 に答える