redgunner Posted August 29, 2010 Share Posted August 29, 2010 How can I set a variable when <a href="#">Link</a> is clicked? for example to set $variableX as integer of 1? Link to comment https://forums.phpfreaks.com/topic/212005-set-variable-on-href-click/ Share on other sites More sharing options...
wildteen88 Posted August 29, 2010 Share Posted August 29, 2010 You'd define it within the query string <a href="file.php?somevar=1">Link</a> You'll use the GET super global for getting the variables from the query string, for this example you'd use the variable $_GET['somevar'] within file.php <?php echo 'Variable is set to: ' . $_GET['somevar']; echo '<p>Lets see what is in the $_GET superglobal: <pre>' . print_r($_GET, true) . '</pre>'; ?> Link to comment https://forums.phpfreaks.com/topic/212005-set-variable-on-href-click/#findComment-1104872 Share on other sites More sharing options...
redgunner Posted August 29, 2010 Author Share Posted August 29, 2010 How could I achieve this with using javascript? Link to comment https://forums.phpfreaks.com/topic/212005-set-variable-on-href-click/#findComment-1104890 Share on other sites More sharing options...
wildteen88 Posted August 29, 2010 Share Posted August 29, 2010 In what way? You can redirect with JavaScript using window.location, eg window.location = 'file.php?somevar=1'; If you don't want the page to reload, then you'll need to use AJAX. Link to comment https://forums.phpfreaks.com/topic/212005-set-variable-on-href-click/#findComment-1104900 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.