Jump to content


This topic is now archived and is closed to further replies.


tricking html to send $_post var with a link.. help please

Recommended Posts

ok im trying to trick html to send a $_POST var with a <a href> link..  im doing this by using some javascript to make the form submit be a text link and not a button or image so the form will send the POST to the .php page..  well when i click the link it does nothing...  here is the javascript.

<script language="JavaScript" type="text/javascript">
function getuser(selecteduser)
  document.usersform.userpicked.value = selecteduser ;
  document.usersform.submit() ;

and the next bit of code is a while loop in php that gets the users from a table in MySQL and sets each user as a link that is supose to call the javascript  but does nothing when i click it.
$result = mysql_query("SELECT genre, user FROM users");
$i = 0;
echo "<form name='usersform' action='member.php' method='post'>";
echo "<input type='hidden' name='userpicked' />";
while ($row = mysql_fetch_object($result)) {
echo "<a href='javascript:getuser($row->user)'>$row->user</a> Genre of choice: $row->genre <br />";
echo "</form>";
echo "$i users signed up";

now the php does everything it is supose to and when i hover over the link i get javascript:getuser(username) at the bottom of firefox. but when i click it i get nothing...

Share this post

Link to post
Share on other sites
Why not use the GET method to pass the variable to the next page?

You may also want to put the username in quotes when you call the js function:

[code]echo "<a href=\"javascript:getuser('$row->user')\">$row->user</a> Genre of choice: $row->genre <br />";[/code]

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.