Can someone help me by giving an example on how to pass php variable into javascript codes and passing back the value/variable back to php (in the same page)?
PHP is server side, Javascript client side. You can only pilot javascript via php, not the opposite.
<?php $test = 5; # php variable
echo "<script> var jstest = '$test'; </script>"; # Assign it to a javascript variable ... ... ?>
Now JS can use it.