In HTML5, returning false in a form gives the red line, indicating there is an error, even though I am able to achieve my expected output. Is there any way to fix this line and have a bug free code as it is triggering my OCD. Also, I am a big beginner with my code so please try to keep it as simple as possible. i do not understand JQUERY at all.
Asked
Active
Viewed 1,388 times
1
-
1does hovering over the red line give helpful message? `i do not understand JQUERY at all.` - you're not using it, so, don't worry about that - you could try `onsubmit="return userRegister1()"` and have `userRegister1` function `return false` – Bravo Mar 26 '22 at 05:37
-
It might just be warning you that if you're doing anything more complicated than calling a single function, you should use an event listener instead of inline JavaScript. But without the detailed explanation of the squiggle, it's hard to know. – Barmar Mar 26 '22 at 05:50
-
@Bravo perhaps jQuery was mentioned because of this? https://stackoverflow.com/a/56296637/3196753 – tresf Mar 26 '22 at 05:58
2 Answers
0
<!DOCTYPE html>
<html lang="en">
<head>
<title>Title of the document</title>
</head>
<body>
<form action="#" method="get" onsubmit="userRegister1(event)">
<input type="text" name="name" />
<button type="submit">Click me</button>
</form>
</body>
</html>
<script>
function userRegister1(event) {
event.preventDefault();
return false;
}
</script>

moo nezam
- 11
- 3
-
Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 26 '22 at 12:49
-2
<form action="#" method="get">
<input type="text" name="name">
<button type="submit" onclick="
// you can code javascript code here, this's same how you code in <script>.....</script>
function userRegister1(){
console.log('your code in userRegister1 function');
}
userRegister1();
// so you return false that's wrong syntax
//onsubmit='userRegister1(); return false;'
// return must be use in function, in this case you can use in function userRegister1()
// BUT i don't suggest use this way
">Click me</button>
</form>

quangdang
- 116
- 7