1

I have a requirement that, i have one html text field initially it should have a default value as 0. But, later point of time i want to change the value of text box ( in ReactJS ).

Am not able to change the default value. Please find my reactjs code for the same.

<input name="discount" type="text" id="header_discount" step="0.01"  maxLength="5" min="0" max="100"  value={ this.state.item.discount ? this.state.item.discount : this.state.item.discount = "0" }  className="form-control" onChange={ this.handleInputChange } />  
1

2 Answers 2

6

You can use default value prop:

<input  defaultValue={0} name="discount" ...
Sign up to request clarification or add additional context in comments.

Comments

0

Set default state on constructor after that change value using handlechange function. your ternary statement on input is not correct.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.