tags:

views:

44

answers:

1

Hi!

I have a page where ID is generated dynamically and be fetch from database and I put the result inside <a> tag :

<?php while($row = mysql_fetch_array($result))
  { ?>
 <a href="<?php echo $row['id']; ?>" onclick="myfunc(); return false;">ID Number 1</a><br />
 <a href="<?php echo $row['id']; ?>" onclick="myfunc(); return false;">ID Number 2</a>
<?php } ?>

and when user click the link, the javascript myfunc() function will be trigger.

function myFunc(){  
  $("#div").load("get_id.php?","id="+"SHOW THE $row['id'] HERE"); }             

But I don't know how to retrieve href value and put it inside the load() method. Can someone show me the correct way?

Thank you

-mike

A: 

Make sure that you generate a complete href attribute:

<a href="get_id.php?id=<?php echo $row['id']; ?>">ID Number 1</a>

and then attach a click handler unobtrusively (don't mix markup and javascript):

$(function() {
    $('a').click(function() {
        $('#div').load(this.href);
        return false;
    });
});
Darin Dimitrov
thanks Darin.. it's work great! :)
mike