niche Posted December 5, 2011 Share Posted December 5, 2011 I need to create a dynamic link. My link is: <a href="javascript:void(0);" onclick="miniatures()">miniatures</a> My js function (so far): function miniatures() {var selection = "miniatures";//send js var to php var//call header} How do I send the value in a js var to a php var? How do I call a header in javascript (load a url)? Link to comment Share on other sites More sharing options...
justsomeguy Posted December 5, 2011 Share Posted December 5, 2011 You can use ajax to send data to PHP. You can set window.location.href to redirect to a different page. If that page needs the information then put it in the URL instead of using ajax. Link to comment Share on other sites More sharing options...
niche Posted December 5, 2011 Author Share Posted December 5, 2011 Thanks for your help JSG.I figured out how to send and use data as part a url (first time working with the $_GET array), but I haven't found the way to turn a js var into a php var with ajax. Can you direct me to the appropriate part of the ajax tutorial? I don't see the part that turns a js var into a php var? Link to comment Share on other sites More sharing options...
thescientist Posted December 5, 2011 Share Posted December 5, 2011 well, you make a request to the script. in the url you pass parameters, which are name/value pairs. i.e www.mydomain.com/myscript.php?param1=somevalue¶m2=someothervalue//orxmlHttpObj.open('GET','myscript.php?param1=somevalue¶m2=someothervalue',false) so, if you are making an AJAX request (POST/GET), or even just an HTTP request via the browsers address bar (only GET), then they are available to the script that way. <?php$param1 = $_GET['param1'];$param2 = $_GET['param2']; echo $param1; //displays 'somevalue'echo $param2; //displays 'someothervalue' ?> if you use AJAX w/POST, then obviously you have to switch to POST in your script instead. Link to comment Share on other sites More sharing options...
justsomeguy Posted December 5, 2011 Share Posted December 5, 2011 You don't "turn a JS var into a PHP var", you send a value from Javascript to PHP, and you can do whatever you want with that value in PHP, including assigning it to a variable. Link to comment Share on other sites More sharing options...
niche Posted December 7, 2011 Author Share Posted December 7, 2011 Thanks for your help justsomeguy and thescientist ( like your new pic). Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.