admin管理员组文章数量:1397142
How to show alert result from javascript return confirm()
?
The script is like this:
<td width="25" align="center" title="Delete">
<?php echo '<a href="'.base_url().'index.php/ticket_controller/confirm_hr_ticket/'.$row->id.'" onclick="return confirm(\'Are you sure to delete '.$row->trans_code.'?\')">'?>
<img style="vertical-align:middle;"src="<?php echo site_url() . 'images/btn_delete.gif'; ?>"></img></a></td>
I want to show alert('Data deleted')
after i click yes in confirmation.
How to show alert result from javascript return confirm()
?
The script is like this:
<td width="25" align="center" title="Delete">
<?php echo '<a href="'.base_url().'index.php/ticket_controller/confirm_hr_ticket/'.$row->id.'" onclick="return confirm(\'Are you sure to delete '.$row->trans_code.'?\')">'?>
<img style="vertical-align:middle;"src="<?php echo site_url() . 'images/btn_delete.gif'; ?>"></img></a></td>
I want to show alert('Data deleted')
after i click yes in confirmation.
-
1
onclick
does not handle boolean value returned byconfirm()
as you want. – Raptor Commented Sep 4, 2013 at 10:17 - 2 Is not related to php. – Ofir Baruch Commented Sep 4, 2013 at 10:18
- sidenote: it is suggested to use CSS instead of HTML attribute for styling. – Raptor Commented Sep 4, 2013 at 10:20
4 Answers
Reset to default 6You need to make a function called by the onclick like
Demo
HTML/PHP
<?php echo '<a href="'.base_url().'index.php/ticket_controller/confirm_hr_ticket/'.$row->id.'" onclick="return myfunction(\''.$row->trans_code.'\')">'?>
Javascript
function myfunction(transcode){
if(confirm('Are you sure to delete '+ transcode + '?'))
{
//Delete data
alert('data deleted');
return true;
}else{
return false;
}
}
Add a simple JS function:
function DeleteClick(transcode)
{
if(confirm('Are you sure to delete ' + transCode + '?'))
{
alert('Data deleted');
return true;
}
return false;
}
Then change your call to
<?php echo '<a href="'.base_url().'index.php/ticket_controller/confirm_hr_ticket/'.$row->id.'" onclick="return DeleteClick(\''.$row->trans_code.'\')">'?>
Write a function in onclick as onclick="confirmclick(userid);"
Javascript function
function confirmclick(userid)
{
var answer = confirm("Are you sure to delete " + userid + "?")
if (answer){
alert('Data deleted');
return true;
}
return false;
}
If you don't want to write separate function then you may use following.
<td width="25" align="center" title="Delete">
<?php echo '<a href="'.base_url().'index.php/ticket_controller/confirm_hr_ticket/'.$row->id.'" onclick="if(confirm(\'Are you sure to delete '.$row->trans_code.'?\')){alert(\'Data deleted\');}">'?>
<img style="vertical-align:middle;"src="<?php echo site_url() . 'images/btn_delete.gif'; ?>"></img></a></td>
本文标签: javascripthow to show return answer from return confirmStack Overflow
版权声明:本文标题:javascript - how to show return answer from return confirm - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744147677a2592914.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论