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.
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.
Share Improve this question edited Sep 4, 2012 at 7:31 Bijoy Thangaraj 5,5464 gold badges45 silver badges73 bronze badges asked Sep 4, 2012 at 7:23 Sam SanSam San 6,9039 gold badges35 silver badges51 bronze badges3 Answers
Reset to default 3change your code like this.
onclick="return del('Are you sure you want to Delete?')"
if(inputs[5].value != '')
{
return confirm(display);
}
<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
Do it like this;
onclick="return del('Are you sure you want to Delete?')"