Home > database >  While button is clicked my local C drive is being opened
While button is clicked my local C drive is being opened

Time:11-14

I was doing a form using HTML and i found that when I'm using my submit button it is showing my local C drive

It doesn't submit my form

CODE:

<div >
    <form id="form" action="/">
        <h1>Registration</h1>
        <div >
            <label for="username">Username</label>
            <input id="username" name="username" type="text">
            <div > </div>
        </div>

        <div >
            <label for="username">Email</label>  
            <input id="email" name="username" type="text">
            <div > </div>
        </div>
        <div >
            <label for="Message">Message </label>  
            <input id="Message" name="username" type="text">
            <div > </div>

            <button type="submit">Sign up</button>
    </form>

CodePudding user response:

Here you can use this logic :

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <form onsubmit="sub(event)">
      <input type="text" name="username" />
      <input type="password" name="password" />
      <button type="submit">save</button>
    </form>

    <script>
      async function sub(ev) {
        // prevents refresh
        ev.preventDefault();
        console.log(ev.target.username.value);
        console.log(ev.target.password.value);
      }
    </script>
  </body>
</html>

CodePudding user response:

In your <form> tag you have used an attribute action='/' which is opened when you click submit button. That is in case of a file the index or your drive default address. If you change it to:

<form id="form" action="#">

it will not redirect to default address.

  • Related