Using javascript confirm box to authenticate user action

dug320

New Member
I have a page with multiple items, and user can delete any of the items right there on the same page. But I need to integrate a javascript confirm alert box to authenticate if the user really wants to continue with the action for each item.I was able to achieve it by placing the javascript in the page but the challenge is that I can only use just one javascript function to delete only one item. This simply means i would be having multiple javascript for each item and that is damn difficult because the number of these items cannot be defined as it keep increasing.So I need to be able to use just one javascript function for all the items being displayed.Here is the javascript code:\[code\]<script> <!--function confirmAlertBox(){ var retVal = confirm("Do you want to continue ?"); if( retVal == true ){ window.location = "items.php?del_item&item_id=<?php echo $item_id; ?>"; return true; }else{ return false; }}//--></script>\[/code\]Here are the items being fetch from the database:\[code\]<?phpwhile ($all_item_row = @mysql_fetch_assoc($all_item_query)) { $item_title = $all_item_row['title']; $item_id = $all_item_row['id']; echo '<tr> <td>'.$item_title.'</td> <td class="action_lnk"><a href="http://stackoverflow.com/questions/14578602/edit_item.php?edit_cal&item_id='.$item_id.'">Edit Item</a> <a href="http://stackoverflow.com/questions/14578602/#" onclick="confirmAlertBox()">Delete Item</a> <div class="clear"></div></td> </tr>';}}else{echo "<strong>No item available. Thank You!</strong>"; }?>\[/code\]
 
Back
Top