score:1
Accepted answer
i see you're storing your enddate
as a state. so, when the user blurs startdate
call validatestartdate
. in that function, use the enddate
state value to validate.
see the pseudo code
<div>
<input type="text" name="startdate" value={this.state.startdate} onblur={this.validatestartdate} />
<input type="text" name="enddate"value={this.state.enddate} onblur={this.validateenddate}/>
</div>
function validatestartdate(){
//check this.state.startdate < this.state.enddate
}
or, you can use refs
to get the enddate
value.
<div>
<input type="text" ref="startdate" name="startdate" value={this.state.startdate} onblur={this.validatestartdate} />
<input type="text" ref="enddate" name="enddate"value={this.state.enddate} onblur={this.validateenddate}/>
</div>
function validatestartdate(){
var startdate= reactdom.finddomnode(this.refs.startdate).value
var enddate = reactdom.finddomnode(this.refs.enddate).value
//check startdate < enddate
}
hope this helps!
score:0
you can use refs supported by react.check here for official documentation
<div>
<input type="text" name="startdate" ref= (input) => {this.startdata = input.value; } value={this.state.startdate} onblur={this.validatestartdate} />
<input type="text" name="enddate"value={this.state.enddate} onblur={this.validateenddate}/>
</div>
in validateenddate
function you can reference the ref.
validateenddate(){
//you can use this.startdate here
}
note: refs do not work in stateless function components
Source: stackoverflow.com
Related Query
- how to pass the value of one input to another input's onBlur event in reactjs?
- How to pass an input value to another input value onBlur event in ReactJs?
- How to dynamically update the value for any input field with one event handler function, using hooks
- How to format value of input for the onBlur event in Formik?
- How to pass state value from one class to another in Reactjs
- How to add https:// in url when input value with http:// or "a.com" onBlur event reactjs
- How to change the value depending on one input when another input is checked? React hooks
- Formik - How do I control the value of another input field automatically when one field changes?
- How to pass a value from this.state from one js file to another reactjs
- How to get state value from Input Slider in one JS file to another - ReactJS
- React : how to get input value from one component to make the ajax call in another component?
- How to pass input value from the search bar to another component?
- how do I call or pass the value from one js file to another file in react js
- How to pass a state value from one component to another component at the same level
- How to copy the one input box to another on click of check box reactjs
- How to pass the Like value from one component to another component using reactjs?
- Updating a React Input text field with the value on onBlur event
- How to trigger INPUT FILE event REACTJS by another DOM
- How to do POST in FORM Submit using reactjs and pass the object value into REST service?
- How can I make the edit-mode field type of one material-table column dependent upon the value of another column, without affecting other rows?
- How to pass data from one component to another ReactJS
- How to pass data from one component to another while using API in reactjs
- How to set input value of one field based on another field in formik?
- How to set the value of inputs with ReactJS hooks?
- How to pass value of a const from one .js file to another in React JS?
- How to pass one state value to another state on initialization in react js
- How to take the input from a react component and pass the length of the input to another react component
- How to pass the variable from one component to another
- How to pass user input from one js file to another
- Pass value from one tab to another tab in ReactJs
More Query from same tag
- Unable to render second react component
- How to access 'this.props.match.params' along with other props?
- Conditional routing in React
- Invoke Lambda function from Amplify-generated React App without using API Gateway
- how to use in Reactjs functional component history.push
- Prevent Re-Render With Modifications to Parent State
- How to keep user joined to their multiple rooms socket.io
- What lifecycle method is the proper one to run validations in child component on button click in another child component?
- local storage problem when trying to fetch data from localstorage using useEffect() in ReactJS
- Getting action is undefined whenever I start my React Application
- Passing props to React Router which contains multiple components
- raw query sequelize node js
- Pass props nicely to screens in react navigation
- Call onChange function each 5 seconds
- Why do I see stale data even after invalidating my queries?
- Cant change variable with callback function but console logging works
- Is there a way to select first on material-ui's autocomplete
- Setting maxLength of input field in react
- use effect run only when a state becomes false
- Does react retain event on subsequent rerenders after assigning it in useEffect?
- How do you customize the material UI select component?
- I want to call a certain parameter from my api
- How to return JSON within a function in React
- Next.js dynamic routing adds to existing path
- Return multiple React elements in a method without a wrapper element
- React + TypeScript: Scroll event type not assignable to window.addEventListener
- How to use material-ui IconMenu inside cell of React fixed-data-table
- Next.js JSON Nested
- Is it possible to add additional user defined properties other than standard properties in "keen" object?
- Get edited row data on click