coupe-r Posted January 18, 2011 Share Posted January 18, 2011 Hi Everyone, I have icons that delete records that use JS to open a Confirm pop up window. My problem is that is JS is not enabled, when a user clicks the icon, it just deletes the record without confirmation. How can I set this up better? Icon via PHP <?php echo '<a href="javascript:void(0);" onclick="deleteEviction(\'eviction.php?id='.$_GET['id'].'&removeRecord=1&del='.$eviction_id.'\');">'. '<img src="../images/tenants/trash.png" alt="Delete Eviction Record" title="Delete Eviction Record" border="0" width="25" height="25" /></a>'; ?> Javascript Function: function deleteEviction (url) { var answer = confirm("You are about to delete the entire eviction record. Do you want to continue?") if (answer){ window.location = url; } else{ return false; } } Quote Link to comment Share on other sites More sharing options...
trq Posted January 18, 2011 Share Posted January 18, 2011 My problem is that is JS is not enabled, when a user clicks the icon, it just deletes the record without confirmation. How can I set this up better? Don't use Javascript to create the confirm message. Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 18, 2011 Share Posted January 18, 2011 My problem is that is JS is not enabled, when a user clicks the icon, it just deletes the record without confirmation. How can I set this up better? Don't use Javascript to create the confirm message. Although I agree that a non-JS confirmation would be a better solution in this instance, from a purely academic perspective there is no reason you cannot implement both. There are plenty of articles about to implement JS that onnly enhances the user experience and not a requirement. In this instance you are using a link to initiate a delete. So, you could implement a JS function for the onclick event which will call for the confirmation and - if true - performs the delete from the js. (by the way I would suggest making a standalone function instead of piling a bunch of code into the onclick event). But, the onclick event should return false. By returning false you are telling the HTML page NOT to follow the href in the link. So, if JS is not enabled the user will go to the href of the link. That href should call an HTML confirmation page. Psuedo code function confirmDelete(recID) { if(confirm('Are you sure you want to delete?')) { window.location = 'deleteRecord.php?id='+recID; } return false; } <a href="htmlConfirmationPage.php?id=12" onclick="return confirmDelete(12);">Delete Record 12</a>[/code[ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.