I have a form that have a button inside. That Button shall not submit the form. It shall trigger a JS-Funktion.
The Button:
$(document).ready(function () {
$('.onlynumbers').keypress(function (e) {
var charCode = (e.which) ? e.which : event.keyCode
if (String.fromCharCode(charCode).match(/[^0-9]/g))
return false;
});
$("#weiter").click(function(event) {
if(parseInt("#wortanzahl".value) > 0){
$("#wk").attr("disabled", false);
alert ("Test");
}
event.preventDefault();
})
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form>
...
<button class="btn btn-success mt-3" id="weiter">Aktualisieren</button>
...
</form>
When I cklick on the Button. Nothing happend. What can it be?
3
Answers
The if condition inside your click handler will never evaluate to true. Remove it and your alert will work.
Any buttons in a form do a submit by default,
you just have to change
by
Here is likely what you want based on the incomplete information you have given: