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.
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;
?>
It will help you ,
<script>
$(document).ready(function() {
$(".next").click(function() {
<?php echo $var = 1 ; ?>
});
});
</script>
<?php
if (!empty($var)) {
echo $var;
}
?>
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.
Do some thing like this.
$(".next").click(function (){
var php_val=$("#php_val").val();//it is getting value from hidden filed whose id is 'php_val'.
//make ajax call with this as follows
$.post("a.php",{php_val:php_val},function(data){
//a.php is page name where u want to send php value.
})
});
<?php $var=1; ?>
<input type="hidden" id="php_val" value="<?php echo $var; ?>"/>
I hope this answers your questions