0

My goal is to have a clickable link "view details" inside of the while loop listing all of the "pubs" that will bring up a popup modal that will display pub_details.php?id=x where x is the corresponding id number.

I need assistance on how to pass the id # to jquery, how to make it a "closeable popup modal", and to not have it open until i click "View Details".

Here is my header jQuery code that I am having some problems with..

<script>
$(document).ready(function() {
$.ajax({
    url: "pub_details.php?id=",
    success: function(data){
    $("#content").html(data);
  }   
});

$("#content").dialog(
    {
        bgiframe: true,
        autoOpen: false,
        height: 100,
        modal: true
    }
  );
});
</script>

Here is my code from my index.php page

$q = "SELECT * FROM ".TBL_PUBS." WHERE status = 'Pending' OR status = 'Active' ORDER BY date_created DESC LIMIT 5 ";
$result = $mysql->query($q);
while($row = $result->fetch_object()) {
  echo $row->id;
  echo "<button id='content'>$row->id</button>";
}
2
  • Just a note about your html - running <button id='content'> in a loop, if more than one iteration, will result in multiple identical html id='content' attributes. You might want to make that class='content' instead, or use id='content-{$row->id}' to make them unique. Commented May 12, 2011 at 2:05
  • Michael, I updated that button to... <input type="button" value="<?=$row->id?>" class="content"></input> Commented May 12, 2011 at 19:25

2 Answers 2

2

Don't use an id for that, use a class. Id's should be unique per page.

Sign up to request clarification or add additional context in comments.

16 Comments

meaning in the <button class='$row->id'>$row->id</button>
<input type="button" value="$row->id" class="content">$row->id</input> Then setup an on click event, $(".content").click(function() { ... }); , that does the ajax request and opens the dialog.
I had to make a <div id="content"></div> with the following jquery code.. When I add ?id=8 it brings be to a blank white page, how can I pass the class variable to it? $(".content").click(function() { $("#content").load("pub_details.php?id=8");});
Made some updates and am almost there... here is my jquery code.. $(".content").click(function() { $(".content").load('pub_details.php').dialog( { modal:true, width:600, height:400}); }); html <input type="button" value="<?=$row->id?>" class="content"></input> My problem is now that it is opening a modal for each of the id's in the while loop. and the modal window is just showing the id # instead of pub_details.php also, how can I pass that variable id to pub_details.php?id=
You're going to need to perform an ajax request inside of the onClick and then on 'success' populate the div and open the dialog.
|
1

See this question: Retrieve Button value with jQuery

Just get the text from you button like this:

$(this).attr("value")

You may need to set the "value" attribute explicitly in your html.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.