0

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

1 Answer 1

0

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;
    });
});
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.