hoopplaya4 Posted January 23, 2009 Share Posted January 23, 2009 Hi All, I have a bit of code: <a href="javascript:showaddevent(2,5,2);">Click Here</a> When clicked, it opens up a form for users to fill out. How would I pass those values in the parenthesis to PHP (2,5,2)? Quote Link to comment Share on other sites More sharing options...
rubing Posted January 23, 2009 Share Posted January 23, 2009 php is on the server. so you would need to use POST or GET methods of communicating them to the server. so, you probably want to use ajax Quote Link to comment Share on other sites More sharing options...
hoopplaya4 Posted January 23, 2009 Author Share Posted January 23, 2009 Good to know. That's what I was thinking the answer would probably be. Does anyone have any recommendation on how to do this? Any specific tutorial or reference? I don't know much with Ajax. Quote Link to comment Share on other sites More sharing options...
haku Posted January 23, 2009 Share Posted January 23, 2009 This book is a great one to start with. Quote Link to comment Share on other sites More sharing options...
rubing Posted January 23, 2009 Share Posted January 23, 2009 If you know php you may want to check out one of the php/ajax frameworks Quote Link to comment Share on other sites More sharing options...
phparray Posted January 23, 2009 Share Posted January 23, 2009 I wrote this tutorial awhile back. It's a quick copy paste, get you started type of thing adopted from w3schools. http://forums.hostmysite.com/about9282.html Quote Link to comment Share on other sites More sharing options...
cwarn23 Posted January 23, 2009 Share Posted January 23, 2009 It is possible to make a link submit a Javascript variable to php at any time but for php to process it in the main page would require a page reload. So basically you setup a link to an invisible iframe and add to the iframe url variables. Then when the iframe loads, it gets the url variables and converts them to session variables. Then those session variables are available to any new page that loads. An example is as follows: <? //index.php echo "<a href='iframe.php?myvar=test&var2=example' target='iframe'>test link.</a>"; echo "<iframe width=1 height=1 scrolling='no' name='iframe' frameborder=0 src='iframe.php'></iframe>"; ?> <? //iframe.php session_start(); foreach ($_GET AS $key => $val) { $_SESSION[$key]=$val; } unset($key); unset($val); ?> In the example above, as soon as the user clicks the link, the following variables will be set: $_SESSION['myvar']=test $_SESSION['var2']=example So it is possible to make variables set at any time but it is just processing or displaying them which is the real trouble. Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted January 23, 2009 Share Posted January 23, 2009 Yes you could use iframes indeed and send the url parameters to that iframe. But why not simply use Ajax it's a lot simpler when you get the hang of it. The ajax tutorial alpine wrote here a couple of years ago still works http://www.phpfreaks.com/forums/index.php/topic,115581.0.html Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.