jeudi 2 avril 2015

Pass javascript variable value to .php using a html form

I have a html form, a variable and a .php script. I would like to pass the value of this variable to the .php script using a html form, it has to be the variables value, so lets say it is 1 then it passes the value 1, but then if the value of the variable changes to 2 then the value the form passes should be 2. Currently when passing the variable, it just passes the name of it.


html:



<form id="get-form" action="getAmount.php" method="POST" name="get-form">
<input type="text" name="amount" id="amount" />
<input type="hidden" id="testVar" name="testVar" value="testVar"/>
<input type="image" src="butImg.png" id="Button" value="pay" alt="but"/>
</form>

<script type="text/javascript">
var testVar= 1;
document.getElementById("testVar").value = testVar;
</script>


php:



$testVar= $_POST['testVar'];

Aucun commentaire:

Enregistrer un commentaire