Home > Mobile >  HTML Form onsubmit
HTML Form onsubmit

Time:03-26

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.

return false here brings a red line. even tried it with the "return <function()> and that also gave red line

CodePudding user response:

<!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>

CodePudding user response:

<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()


        ">Click me</button>
    </form>
 

  • Related