I try to make form where enter in fields does not submit form, so I tried disable submitting with onsubmit="return false;"
, but then <button type="submit">
would disabled too. So I tried to POST through javascript, like that:
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<form method="post" onsubmit="return false;" name="form">
<input type="text" name="foo">
<input type="text" name="bar">
<button onclick="submitForm()" name="btn" value="one">one way</button>
<button onclick="submitForm()" name="btn" value="another">another</button>
</form>
<script type="text/javascript">
function submitForm(argument) {
document.form.submit();
}
</script>
</body>
</html>
Problems now:
- clicking on button submits form, but does not include values of button
- enter in text inputs submits again the form
In submitting function I could set some form value depending clicked button, but is there better way? And still, submitting with enter is not disabled.
How is best way to reach both goals?
PS! I am aware of Prevent users from submitting a form by hitting Enter and part of my example is inspired from one solution there. My example should show other problems too.