View Full Version : jQuery/Ajax - Get the value of a hyperlink.

07-29-2008, 08:35 AM
Hi All,

I have a search user option on my webpage (search.php) where people can search for a product. The processing part is done on a separate php page (process.php)

The code for process.php page is:

$name = $_GET['txtnamesearch'];
$result = mysql_query("select username,full_name from login where username LIKE'$name%' or full_name LIKE'$name%'");
$num_rows = count($result);
echo "<B>Oouchhh!! Try refining your search.</b>";
echo '- '.$result[$x]['full_name'] .' => <a id='.$result[$x]['username'].'>'. $result[$x]['username']. '</a><BR>';
}//End Search User

The result on the search.php page will output as the following :

Search Results:
- Sam Thomas => sam (process.php?user=sam)
- John Clinger => jon (process.php?user=jon)
- Patrick Norton => pat (process.php?user=pat)

Now, I want such that clicking on each username would display their profile details.

What ajax call do I have to make and how?


08-19-2008, 02:59 PM
It depends where you want to display it, and where/how that content gets generated

Personally I'd make the links real, with an href set to the page that would display the profile (based on id, or something like that). then five them a class, or the parent element an id or something so that they can be identified.

Then you need a container to put the ajaxed content into


<b>Search Results:</b><br>
- Sam Thomas =&gt; <a class='ajax' href=process.php?user=sam" target="_blank">sam</a><br>
- John Clinger =&gt; <a class='ajax' href="process.php?user=jon" target="_blank">jon</a><br>
- Patrick Norton =&gt; <a class='ajax' href="process.php?user=pat" target="_blank">pat</a><br>
<div id='profile'>
<!-- ajaxed profile content gets put in here -->

then you can use jquery's 'load' function

$(function() {
$("a.ajax").click(function() {
return false;

This isn't real AJAX as it doesn't use XML, it's more asynchronous http and HTML (AHAH)