Reputation: 6903
This is my code:
<input type="submit" value="Delete" onclick="del('Are you sure you want to Delete?')">
<script language="JavaScript">
function del(display)
{
var inputs = document.myform;
if(inputs[5].value != '')
{
confirm(display);
}
}
</script>
When I click either the "ok" or the "cancel", they both did the same way (the OK way)
How can I make the "cancel" do what it is supposed to do?
NOTE: I have a form there that I didn't include for the simplicity of question.
Upvotes: 0
Views: 6981
Reputation: 2509
change your code like this.
onclick="return del('Are you sure you want to Delete?')"
if(inputs[5].value != '')
{
return confirm(display);
}
Upvotes: 3
Reputation: 33993
Do it like this;
onclick="return del('Are you sure you want to Delete?')"
Upvotes: 0
Reputation: 123367
<input type="submit" value="Delete" onclick="return del('Are you sure you want to Delete?')">
<script language="JavaScript">
function del(display)
{
var inputs = document.myform;
if(inputs[5].value != '')
{
return confirm(display);
}
}
</script>
you need to add two return
in your code (both onclick
attribute and inside del()
function). You should also return something if your condition inputs[5].value != ''
is false
Upvotes: 2