[英]Send javascript function variable with form
我需要发送带有表单的javascript函数返回的变量。
<form name="RegForm" method="post" action="/validate_accountinfo.php" onsubmit="send()">
</form>
function send()
{
var number = 5;
return number;
}
在validate_accountinfo.php中,我想返回该函数的值。 这个怎么做?
在表单中放置一个隐藏字段,然后在javascript函数中设置其值。
隐藏字段:
<input type="hidden" id="hdnNumber">
JavaScript:
function send(){
var number = 5;
document.getElementById("hdnNumber").value = number;
}
将<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>
创建一个<input type="hidden" id="field" />
并使用jQuery更新其值。
$("#field").attr({value: YourValue });
添加隐藏的输入并在发送之前填充它。 确保指定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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.