Skip to content

Latest commit

 

History

History
58 lines (37 loc) · 2.73 KB

File metadata and controls

58 lines (37 loc) · 2.73 KB

React and Forms

Forms

HTML Form is a document which stores information of a user on a web server using interactive controls. An HTML form contains different kind of information such as username, password, contact number, email id etc. The elements used in an HTML form are check box, input box, radio buttons, submit buttons .

HTML form elements work a bit differently from other DOM elements in React, because form elements naturally keep some internal state. For example, this form in plain HTML accepts a single name

Controlled Components

In HTML, form elements such as <input, <textarea, and <select typically maintain their own state and update it based on user input. In React, mutable state is typically kept in the state property of components, and only updated with setState(.if we want to make the previous example log the name when it is submitted, we can write the form as a controlled component

class NameForm extends React. Component { constructor(props) { super(props); this. state = {value: ''}; this. handleChange = this. handleChange. bind(this); this. handleSubmit = this. handleSubmit. bind(this); } ​

user intreance

Get the value of input type checkbox function getChecked() { const checkBox = document. getElementById('check1'). checked; if (checkBox === true) { console. log(true); } else { console. log(false);

First, select the element with the id message and the

element with the id result . Then, attach an event handler to the input event of the element. Inside the input event handler, update the textContent property of the

element.

ternary operator

Use the ternary operator to simplify your if-else statements that are used to assign values to variables. The ternary operator is commonly used when assigning post data or validating forms

  • What is the use of ternary operator in C?

The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark ( ? ), then an expression to execute if the condition is truthy followed by a colon ( : ), and finally the expression to execute if the condition is falsy.

Things I want to know more about

know more about how to creat a form in parctic

for more info please visit my github qusaiqeisi

best regard