Reputation: 845
I am trying the submit the form on button click but want user to confirm whether he is sure or not. I have mutiple submit button on form and I just want pop-up in case of delete. When I make the type of my button submit. My form gets submitted twice If I confirm else It gets submitted once (I don't want it to submitted in that case).
I have multiple form on the page. That's why I am trying to submit the form getting parent Node and not using getElementbyId.
JavaScript function
function deleteEvent(btn){
var confirmed=confirm('Do you want to delete the event?');
if(confirmed){
var f = btn.parentNode;
f.submit();
}
else{
return false;
}
}
HTML Code
<form action="#" method="POST">
<input type="button" name="delete" value="Delete" onClick ="deleteEvent(this)">
</form>
Thanks.
Working Solution:
<input type="submit" name="delete" value="Delete" onClick ="return confirm('Do you want to delete the event?');">
Upvotes: 0
Views: 2147
Reputation: 8726
try this
use onclick="return deleteEvent(this);" if button type is submit
<input type="submit" name="delete" value="Delete" onclick="return deleteEvent(this);">
Upvotes: 2