Jump to content

javascript confirm boxes for list of messages


dadamssg

Recommended Posts

I'm not really familiar with javascript but i've come up with a confirm box that asks if they really want to delete a message but i don't know how to incorporate it into a while loop. I'm listing out all subjects of messages sent to a person. And then i have an X next to each one for them to click and when they do i want the confirm box to pop up. I just don't know how to incorporate this in the head

<script type="text/javascript">
function show_confirm()
{
var r=confirm("Really delete?");
if (r==true)
  {
  window.location = "deletemessage.php?ms=<?php echo $row['messageid']; ?>"
  }
else
  {
  }
}
</script>

with this while loop in the body

while ($row = mysqli_fetch_assoc($result)) {  
echo "<div id='mwrap'><div id='mwidth'><div id='floatl'>{$status}</div><div id='floatr'><a href= profile.php?uu={$row['sentby']} class='profile'>{$row['sentby']}</a><br><div class='user'>{$time}</div></div></div>";
echo "<div id='twidth'><a href = showmessage.php?ms={$row['messageid']} class='subject'>{$id}</a></div>";
echo "<div id='delete'><a href ='#' onclick='show_confirm()' class='delete'>X</a></div></div>";                                         }
echo "<br>";

the problem right now is that the confirm box only pulls up the number for the first message....so all of the X's link to the same exact alert box

Link to comment
Share on other sites

Pass the id in the while loop, receive it in the javascript function.

<script type="text/javascript">
function show_confirm(mid)
{
  var r=confirm("Really delete?");
  
  if (r==true){
    window.location = "deletemessage.php?ms=" + mid;
  }
}
</script>

(this above could be made more nifty with ajax)

 

...
echo '<div id="delete"><a href ="#" onclick="show_confirm(\'" . $row['messageid'] . "\')" class="delete">X</a></div></div>'; 

 

Should be something similar to that. not tested.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.