SEND JAVASCRIPT FUNCTION VARIABLE WITH FORM

Samuel Fernandes

Total Post:159

Points:1117
Posted by  Samuel Fernandes
 1704  View(s)
Ratings:
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.

  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Send javascript function variable with form

    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>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!