I am trying to prevent the submission of a button when pressed. But with my javascript code, the button still refreshes the page when the submit button is pressed. Here's my code (doesn't work):
<html>
<head>
<title>tangina</title>
</head>
<body>
<form action="POST" class='user-signup-form'>
{% csrf_token %}
<input type="text">
<button type="submit">submit</button>
</form>
<script>
$(document).ready(function(){
var userForm = $(".user-signup-form")
userForm.submit(function(event){
event.preventDefault();
})
});
</script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</body>
</html>
this is just a simple code, I'm just trying to try to prevent the button from submitting form when pressed. What am I doing wrong here?