-
Notifications
You must be signed in to change notification settings - Fork 40
/
Select date picker in React Js
62 lines (54 loc) · 1.79 KB
/
Select date picker in React Js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React, { useState } from "react";
import { Container } from "react-bootstrap";
function Datepicker()
{
const [name, setName]= useState('');
const [newdate, setNewdate]= useState([]);
const handlename =(e)=>{
const getnamevalue= e.target.value;
setName(getnamevalue);
//console.log(getdatevalue);
}
const handledate =(e)=>{
const getdatevalue= e.target.value;
setNewdate(getdatevalue);
//console.log(getdatevalue);
}
const handleSubmit =(e)=>{
e.preventDefault();
alert("get name"+name+" get date"+ newdate );
}
return(
<React.Fragment>
<Container>
<div className="row fthight">
<div className="col-sm-8 mt-3">
<h4 className="mb-4">How to select date picker in react js </h4>
<form onSubmit={ handleSubmit}>
<div className="row mb-4 ">
<label className="col-sm-2 col-form-label">Name<span className="astriccolor">*</span></label>
<div className="col-sm-5">
<input type="text" className="form-control" name="name" onChange={(e)=>handlename(e)} />
<span className="text-danger"> </span>
</div>
</div>
<div className="row mb-4 ">
<label className="col-sm-2 col-form-label">Date<span className="astriccolor">*</span></label>
<div className="col-sm-5">
<input type="date" className="form-control" name="todate" placeholder="dd-mm-yyyy" onChange={(e)=>handledate(e)} />
</div>
</div>
<div className="row mb-4 ">
<label className="col-sm-2 col-form-label"></label>
<div className="col-sm-5">
<button className="btn btn-success"> Submit </button>
</div>
</div>
</form>
</div>
</div>
</Container>
</React.Fragment>
);
}
export default Datepicker;