I have a form with several <input>
fields, and a series of <button>
elements. Every button has a value and I want this value to be sent on submit. Here is an example:
<!doctype html>
<title>test</title>
<meta charset="utf-8">
<script src="../node_modules/jquery/dist/jquery.min.js"></script>
<body>
<form>
<button type="submit" name="launch" value="one">one</button>
<button type="submit" name="launch" value="two">two</button>
</form>
<script>
$("form").on('submit', function(e){
e.preventDefault();
console.log($("form").serializeArray())
});
</script>
- Without
preventDefault()
, I have correctly?launch=one
on submit. - With
preventDefault()
, I have an empty array in the console log.
Why? How can I avoid it?