Today I have learned Form in javascript

 Form in javascript:

  • Form name tag is used to define the name of the form. The name of the form here is "Login_form". This name will be referenced in the JavaScript form.
  • The action tag defines the action, and the browser will take to tackle the form when it is submitted. Here, we have taken no action.
  • The method to take action can be either post or get, which is used when the form is to be submitted to the server. Both types of methods have their own properties and rules.
  • The input type tag defines the type of inputs we want to create in our form. Here, we have used input type as 'text', which means we will input values as text in the textbox.
  • Net, we have taken input type as 'password' and the input value will be password.
  • Next, we have taken input type as 'button' where on clicking, we get the value of the form and get displayed.
  • When we submit the form, the action is taken just before the request is sent to the server. It allows us to add an event listener that enables us to place various validations on the form. Finally, the form gets ready with a combination of HTML and JavaScript code.

    Let's collect and use all these to create a Login form and SignUp form and use both

  •  <form>
      <label for="fname">First name:</label>
    <input type="text" id="fname" name="fname" />
            <br />
            <label for="lname">Last name:</label>
            <br />
            <input type="text" id="lname" name="lname" value="Kumar" />
            <br /> <br />
    <input type="radio" id="html" name="fav_language" value="HTML1" />
            <label for="html">HTML</label>
            <br />
            <input type="radio" id="css" name="fav_language" value="CSS" />
            <label for="css">CSS</label>
            <br />
            <input type="radio" id="js" name="fav_language" value="JS" />
            <label for="javascript">JavaScript</label>
            <br />
            <br />
            <input type="checkbox" value="Apple1" id="apple1" name="fruit" />
            <label> I have an Apple</label>
            <br />
            <input type="checkbox" value="Orange1" id="orange1" name="fruit" />
            <label> I have an Orange</label>
            <br />
            <input type="checkbox" value="Grapes1" id="grapes1" name="fruit" />
            <label> I have a Grapes</label>
            <br />
            <label for="phone number">Phone number:</label>
    <input type="number" id="phone number" name="phone number" />
    <br></br>
            {/* input for type="submit" it will appear as button */}
            <input type="submit" value="Submit" />
            <br></br>
            <label for="comment">Comments:</label>
    <textarea class="form-control" rows="5" id="comment" name="text"></textarea>
            </form>
  • Output:





Comments

Popular posts from this blog

Building a Full-Stack Student Management System with React.js and NestJS

Today I have solved the problem in javascript

Today I have solved problem in javascript