Hi would like to call a function if the answer to return confirm is yes, just don't know where to put the myFunction(). my code is below.
<a href="#" onClick="return confirm('Are you sure your want to delete?')">Delete</a>
Hi would like to call a function if the answer to return confirm is yes, just don't know where to put the myFunction(). my code is below.
<a href="#" onClick="return confirm('Are you sure your want to delete?')">Delete</a>
Share
Improve this question
asked Apr 28, 2017 at 5:35
KaoriYuiKaoriYui
9221 gold badge16 silver badges44 bronze badges
6 Answers
Reset to default 2Try it like,
<a href="#"
onClick="if(confirm('Are you sure your want to delete?')){alert('Delete');} else {alert('Dont delete')}">
Delete</a>
Snippet,
<a href="#"
onClick="if(confirm('Are you sure your want to delete?')){alert('Delete');} else {alert('Dont delete')}">
Delete</a>
try to wire the method call with &&
<a href="#" onClick="confirm('Are you sure your want to delete?') && myFunction() ">Delete</a>
Use like this .Don't use the confirmation inline of the onlclick
- Declare the
myfunction
in onclick - Then apply the confirmation inside the function
function myfunction(){
if(confirm('Are you sure your want to delete?')){
//do stuff
console.log('yes')
}
}
<a href="#" onClick="myfunction()">Delete</a>
onClick="return confirm('Are you sure your want to delete?') && Yourfunction() "
Use it like this
<a href="#" onClick="confirmDelete()">Delete</a>
<script type="text/javascript">
function confirmDelete()
{
if(confirm('Are you sure your want to delete?'))
{
/* Perform operations */
}
}
</script>
Use this
$(document).ready(function(){
$("#myID").on("click",function(){
if(confirm){
alert('enter your code here');
}
});
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="#" id="myID">Delete</a>