How To Select A Button Inside A Form Tag With Javascript?
I am trying to make a confirmation message popup when submitting a form using the bootbox plugin. The problem is that I don't know how to select the button inside the form tag. In
Solution 1:
Change javascript code to:
<scripttype="text/javascript">
$(document).ready(function(){
$('.btn').on('click', function(e){
e.preventDefault(); // this line is key to preventing page reload// when user clicks submit button inside form
bootbox.alert("hello there");
});
});
</script>
Solution 2:
Why don't you catch the submit event of the form?
Give your form an id like "<form method="POST" id="my_form">...</form>"
and use:
$('#my_form').submit(function(){
bootbox.alert("hello there");
});
Take a look at your fiddle here!
Post a Comment for "How To Select A Button Inside A Form Tag With Javascript?"