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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.