Home > DeveloperSection > Forums > Send javascript function variable with form
Samuel Fernandes
Samuel Fernandes

Total Post:156

Points:1096
Posted on    March-12-2013 3:24 AM

 JavaScript JavaScript 
Ratings:


 1 Reply(s)
 1436  View(s)
Rate this:

Hi Everyone!

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?

Thanks for advance.



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    March-12-2013 8:46 AM

Hi Samuel!

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>


Don't want to miss updates? Please click the below button!

Follow MindStick