Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing a variable with href in html [closed]

Tags:

html

php

I want to pass a variable along with the link on a button click, while using href. can anyone tell me the exact syntax or if it is even possible? i want to do something like this: href="link+variable" so that i can extract the variable and use it on the "link" which will open.

like image 953
Delphinium Avatar asked Oct 27 '12 17:10

Delphinium


2 Answers

Yes it is possible by doing the following

site 1

<input type="button" onClick="window.location='http://example.com?var=<?php echo $var ?>'">

On the recieving site use the following:

site 2

<?php
    $var = $_GET['var'];
?>

The variable you sent is store in $var in site 2

like image 165
Lennart Avatar answered Sep 26 '22 01:09

Lennart


Do you mean passing a value as a parameter?

<a href="page.php?value_key=some_value">Link</a>

Then in PHP

if(isset($_GET['value_key'])){
  $var = $_GET['value_key']; //some_value
}
like image 39
Lawrence Cherone Avatar answered Sep 22 '22 01:09

Lawrence Cherone