Jump to content


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

  • Please log in to reply
2 replies to this topic

#1 just-j

  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts

Posted 18 July 2006 - 09:30 PM

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...

#2 hitman6003

  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 18 July 2006 - 09:43 PM

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:

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

#3 just-j

  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts

Posted 18 July 2006 - 09:49 PM

that works  thanks!!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users