submiting a form

how can i prevent a form from submit .i try it suing the JavaScript but it doesn't work
3 Replies
Jochem
Jochem2y ago
event.preventDefault() in an onsubmit handler form submissions are 100% frontend though, it's the browser doing the submitting
BERSERK
BERSERKOP2y ago
i try it but form have the attribute action="file_name.php";
Jochem
Jochem2y ago
that shouldn't matter
<form id="myform" action="file_name.php">
<input type="text" name="test" value="testing" />
<button type="submit">Submit</button>
</form>
<script>
document.getElementById('myform').addEventListener("submit", (e) => e.preventDefault());
</script>
<form id="myform" action="file_name.php">
<input type="text" name="test" value="testing" />
<button type="submit">Submit</button>
</form>
<script>
document.getElementById('myform').addEventListener("submit", (e) => e.preventDefault());
</script>
that should prevent the form submitting
Want results from more Discord servers?
Add your server