In same page i set the jquery value while click the button. i want pass the value to php variable in same page without form submitting.
<input type="button" name="next" class="next btn btn-primary" value="Proceed To Checkout Page" />
Jquery
$(".next").click(function(){
<?php $var1="1";?>
}
While check the php value
<?php if(isset($var1)){
echo $var1;
}else{
echo "NULL";
}?>
Every time time i got the null value. Where i getting mistake. Ps: I cant able to send the ajax call to get the value
If at all you want to send php value to php page using jquery and ajax, then first of all, create input text with type hidden. put your php value in it. and when you click then get that value from that input type hidden in jquery and then pass it to whichever page you want.
To Set PHP Variable in JavaScript, we define a JS variable and assign PHP value using PHP tag with single or double quotes. Most of the time you have to set PHP variable value in JavaScript. If there is only simple variable like string or any integer then you can simply echo on the JS variable with PHP tag.
You simply cannot do that, you need to understand the difference between client/server side programming, you cannot assign Javascript value to PHP variable, yea but you can assign PHP value to your javascript.
You can use cookies to achieve this.
In Javascript:
<script type="text/javascript">
document.cookie = "var1=1";
</script>
And in PHP
<?php
$phpVar = $_COOKIE['var1'];
echo $phpVar;
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With