Reputation: 865
Is it possible to send the contents of a JavaScript variable to PHP when a form is submitted?
Upvotes: 1
Views: 105
Reputation: 16027
Yes. Just add a javascript callback to the form submit event
<script type="text/javascript">
var myglobalvariable = "myvalue";
onSubmit = function(){
document.myform.myinput.value = myglobalvariable; return true;
}
</script>
<form name="myform" id="myform" method="post" action="index.php" onsubmit="onSubmit();">
<input name="myinput" id="myinput" type="hidden" />
</form>
Upvotes: 3