Hello, How i can transfer a Javascript value to PHP? I'm using the following code but for some reason is not working: <script> function ServerLocation() { var ServLoc="none"; if (document.ServLink.link[0].checked) ServLoc=ServLink.link[0].value; if (document.ServLink.link[1].checked) ServLoc=ServLink.link[1].value; location=ServLoc; } var ServerLocation = "<?=$PHPServerLocation?>"; </script> Code (markup): and after a radio button is checked i echo the $PHPServerLocation <?php echo $PHPServerLocation; ?> Code (markup): Thanks in advance!
Hi, this won't work, because every line of PHP is executed before the page is sent to your browser. So when you are able to click on an element such as a checkbox, PHP is done and is not influenced by your actions. To pass a variable to PHP you would need to reload the page with a parameter defining the value, or use ajax-like methods.
So the only solution is to create a link (value is a link URL) that gets the javascript value? <a href="#" onClick="ServerLocation()">Link</a> Code (markup):
try this one... function ServerLocation() { var ServLoc="none"; if (document.ServLink.link[0].checked) ServLoc=ServLink.link[0].value; if (document.ServLink.link[1].checked) ServLoc=ServLink.link[1].value; location=ServLoc; } var ServerLocation = "urphppage.php?valuename="+valuetobepassed; xmlHttp.open("GET",ServerLocation,"true"); PHP: on the urphppage.php echo $_GET['valuename']; PHP: hope this helps..