plutomed Posted September 1, 2007 Share Posted September 1, 2007 Is there a way to do this??? Link to comment https://forums.phpfreaks.com/topic/67562-solved-_get-in-javascript/ Share on other sites More sharing options...
php_tom Posted September 1, 2007 Share Posted September 1, 2007 You didn't really describe exactly what you want to do... I'm guessing you have something like this in mind (?): <script> var get_variable = '<?php echo $_GET['variable']; ?>'; alert(get_variable); </script> If not, please explain more. Link to comment https://forums.phpfreaks.com/topic/67562-solved-_get-in-javascript/#findComment-339402 Share on other sites More sharing options...
plutomed Posted September 1, 2007 Author Share Posted September 1, 2007 I know how to do it that way I guess I could do it like that. Is there no way to do it with javascript then coz It's in the *.js file at the moment. Link to comment https://forums.phpfreaks.com/topic/67562-solved-_get-in-javascript/#findComment-339409 Share on other sites More sharing options...
php_tom Posted September 1, 2007 Share Posted September 1, 2007 I see... I found this somewhere in the vast cavern of knowledge we call the web: <script> function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i<vars.length;i++) { var pair = vars[i].split("="); if (pair[0] == variable) { return pair[1]; } } alert('Query Variable ' + variable + ' not found'); } </script> Now make a request to page.html?x=Hello <script> alert( getQueryVariable("x") ); </script> Note that it only works with GET, not POST. Hope that helps. Link to comment https://forums.phpfreaks.com/topic/67562-solved-_get-in-javascript/#findComment-339422 Share on other sites More sharing options...
plutomed Posted September 1, 2007 Author Share Posted September 1, 2007 Yea I thought about doing it with the split but I thought again because I need a specific one out of the URL. I think I will just put the JS at the top of the page and use php. Thanx anyways. Link to comment https://forums.phpfreaks.com/topic/67562-solved-_get-in-javascript/#findComment-339424 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.