Reputation: 11829
I need to send a variable returned from a javascript function with a form.
<form name="RegForm" method="post" action="/validate_accountinfo.php" onsubmit="send()">
</form>
function send()
{
var number = 5;
return number;
}
In the validate_accountinfo.php I want to return the value of the function. How to do this?
Upvotes: 0
Views: 184
Reputation: 4259
Add a hidden input and populate it before sending. Make sure you specify a name=
attribute.
<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;
}
Upvotes: 0
Reputation: 1436
Place a hidden field in your form, and set its value in your javascript function.
Hidden field:
<input type="hidden" id="hdnNumber">
JavaScript:
function send(){
var number = 5;
document.getElementById("hdnNumber").value = number;
}
Upvotes: 1
Reputation: 1805
Make a <input type="hidden" id="field" />
and update it's value with jQuery.
$("#field").attr({value: YourValue });
Upvotes: 0
Reputation: 8805
Add an <input hidden id="thevalue" name="thevalue" />
to the form, set its value using javascript and then submit the form.
<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>
Upvotes: 0