views:

30

answers:

2

I have a list of names (1-15 rows) I display from an array. I want the administrator to select the correct name from the list by clicking on the hypertext called "link." The record id is in the array and I want that passed to the called script.

I found this javascript that works except that I want the linkur.php page to print (with its information messages). I know it doesn't print because of the void(0) but can not figure the correct method needed.

<a href="javascript:void(0);" onclick='$.get("linkur.php",{ rid: "<?php echo $k['id']; ?>", uid: "<?php echo $uid; ?>", } ,function(data){ $("#link<?php echo $k['id']; ?>").html(data); });'>Link</a>

Also, is it possible to do the hyperlink with pure HTML? The hyperlink is straight forward except for passing the array values.

Thanks for any ideas.

Carl

+1  A: 

I'm a bit confused by your request. You don't mention needing an asynchronous request, yet that is what your code is doing using the jQuery library. If you don't need an asynchronous request, and want to see the end-page, you just build a regular link:

<a href="linkur.php?rid=<?php print $rid; ?>&uid=<?php print $uid; ?>">Link</a>

This would be rendered on the page with solid values rather than variables:

<a href="linkur.php?rid=123&uid=281">Link</a>

Once you clicked the link, you would pass rid=123 and uid=281 to the end-script, seeing its output on the screen.

Properly Adding some Asynch'ness

If you need to load this data asynchronously, there is only a small addition to the code. Keep the original link that we just referenced above, but add a class to it:

<a href="linkur.php?rid=123&uid=281" class="loadme">Link</a>

Now with jQuery we can incercept these requests and load up their HTML elsewhere:

$(function(){
  // Intercept the click event of our links
  $(".loadme").click(function(e){
    // Prevent them from leaving the page
    e.preventDefault();
    // Fire off a request for their content
    $.get($(this).attr("href"), function(data) {
      // Load their content into a container on our page
      $("#content-viewer").html(data);
    }, "html");
  });
});

Note that I referenced a #content-viewer. You would need to have this on your page someplace:

<div id="content-viewer">I will show the content .loadme links!</div>
Jonathan Sampson
A: 
Tatu Ulmanen
Thanks a lot guys. I appreciate all the work you did-WOW! My problem really was just passing the array value for the id in the hyperlink. I found that I could pass an array value with php by using the code " . $k['id'] . " and so the solution to my problem became simple once I learned this. Here is the statemnt that does the job:echo "<a href='linkur.php?rid=" . $k['id'] . "
Carl