I have several links in an HTML page (say some 100 - 120). What I exactly need is to send different data to another PHP page (say display.php) when I click on each link. I tried a pathetic method,
<form action="display.php" method="post"> // or GET
<input type="hidden" name ="data" value="Data1" />
<input type="submit" value="Link 1" />
</form>`
.
.
.
<form action="display.php" method="post">
<input type="hidden" name ="data" value="Data120" />
<input type="submit" value="Link 120" />
</form>
Is there any simple way to reduce the usage of these 120 forms?
You can put data directly on the href of your tag.
Ex:
<a href="./display.php?data=Data1&data2=Data120">Click here</a>
Then in your display.php file :
<?php
if(isset($_GET["data"]) && isset($_GET["data2"]))
{
$data = $_GET["data"];
$data2 = $_GET["data2"];
}
?>
Here you go.
yes sure try to use tags with id's
<a href="display?data=data1">link1</a>
hope this helps
Try this
<form action='display.php' method='post'>
<input type="submit" value="Link 1" name='1' onclick='setHidden(this)'/>
<input type="submit" value="Link 2" name='2' onclick='setHidden(this)'/>
<input type="submit" value="Link 3" name='3' onclick='setHidden(this)'/>
<input type="submit" value="Link 4" name='4' onclick='setHidden(this)'/>
<input type="hidden" id='data' name ="data" value="" />
</form>
// Javascript
<script type='text/javascript'>
function setHidden( key)
{
var dataStr='Data';
dataStr+=key.name;
document.getElementById('data').value=dataStr;
}
</script>
then in display.php file
<?php
if(isset($_POST['data']))
{
$data=$_POST['data'];
echo $data;
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With