I'm struggling with this problem and can't figure it out. Here's what I've done:
Form:
<form method="POST" action="search.php" name="form" id="form">
<input type="text" name="search" id="search" placeholder="Introduza a sua Localização">
<input type="submit" name="Submit" value="Pesquisar">
</form>
php looping:
<?php if (mysql_num_rows($tournaments) !=0){
do {
?>
<div id="rightDetails">
<i class="fa fa-gamepad"></i> <a href="games.php?id_game=<?php echo $row_tournaments['id_game']; ?>"><?php echo $row_tournaments['game']; ?></a><br>
<i class="fa fa-calendar-o"></i> <a href="#"><?php echo $row_tournaments['date']; ?></a><br>
<i class="fa fa-pencil-square-o"></i> <a href="tournaments.php?id_tournament=<?php echo $row_tournaments['id_tournament']; ?>#disqus_thread">Sem comentários</a><br>
<i class="fa fa-map-marker"></i> <a onClick="giveThatInputAValue()"><?php echo $row_tournaments['location']; ?></a><br>
<img src="images/<?php echo $row_tournaments['online']; ?>.png"> <a href="#"><?php echo $row_tournaments['online']; ?></a>
</div>
<?php } while ($row_tournaments = mysql_fetch_assoc($tournaments));
} else {
?>
<div id="noresults"><p>Sem Torneios</p></div>
<?php
}
?>
function:
function giveThatInputAValue(){
var elem = document.getElementById("search");
elem.value = "<?php echo $row_tournaments['location']; ?>";
document.forms["form"].submit();}
So when i press,
<a onClick="giveThatInputAValue()"><?php echo $row_tournaments['location']; ?></a>
The input value will change the value from input and submit form after, but the problem remains: how can i put this function inside the loop, so the value changes to the proper value from database?
This value is being loaded correctly: <?php echo $row_tournaments['location']; ?>
But outside the loop it always shows the first result from the database.
Please help can't figure it out.