I am currently looking for a way on how can I access a javascript variable and use it in my php script (same page). I heard about using ajax, but I don't really know where to start, I have little experience when using ajax, could someone please help me start with this problem? The code below is just an example on what I am trying to do:
<script>
var fruit = "apple";
</script>
I am trying to get the value of the variable fruit for example using a php script
<?php
$fruit = code to get the value maybe....
?>
My example above must be wrong and I know ajax is the way to go, but could someone please help me on how to approach or start with it? I would appreciate it! Thanks!