Created
December 10, 2020 22:08
-
-
Save fadihanna123/a0ddb528353717af66b1c093789ba967 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from "react"; | |
const App = () => { | |
const [form, setForm] = useState({ uname: "", cars: "", sex: "" }); | |
const typer = (e) => { | |
setForm({ ...form, [e.target.name]: e.target.value }); | |
}; | |
const Show = () => { | |
console.log(form); | |
}; | |
return ( | |
<> | |
<div className="container-fluid mt-2"> | |
<div className="row mb-3"> | |
<div className="col-md-1"> | |
<label htmlFor="uname" className="col-form-label"> | |
Username: | |
</label> | |
</div> | |
<div className="col-md-2"> | |
<input | |
value={form.uname} | |
onChange={typer} | |
type="text" | |
id="uname" | |
name="uname" | |
className="form-control" | |
/> | |
</div> | |
</div> | |
<div className="row mb-3"> | |
<div className="col-md-1"> | |
<label htmlFor="cars" className="col-form-label"> | |
Cars: | |
</label> | |
</div> | |
<div className="col-md-2"> | |
<select | |
id="cars" | |
name="cars" | |
value={form.cars} | |
onChange={typer} | |
className="form-control" | |
> | |
<option value="">---</option> | |
<option value="volvo">Volvo</option> | |
<option value="volkswagen">Volkswagen</option> | |
</select> | |
</div> | |
</div> | |
<div className="row mb-3"> | |
<div className="col-md-1"> | |
<label htmlFor="sex" className="col-form-label"> | |
Sex: | |
</label> | |
</div> | |
<div className="col-md-2" onChange={typer}> | |
<div className="form-check form-check-inline"> | |
<input | |
className="form-check-input" | |
type="radio" | |
name="sex" | |
value="man" | |
/> | |
<label className="form-check-label" htmlFor="man"> | |
Man | |
</label> | |
</div> | |
<div className="form-check form-check-inline"> | |
<input | |
className="form-check-input" | |
type="radio" | |
name="sex" | |
value="woman" | |
/> | |
<label className="form-check-label" htmlFor="kvinna"> | |
Kvinna | |
</label> | |
</div> | |
</div> | |
</div> | |
<button onClick={Show} className="btn btn-primary"> | |
Visa | |
</button> | |
</div> | |
</> | |
); | |
}; | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment