# Create a Controlled Input help

**URL:** <https://forum.freecodecamp.org/t/create-a-controlled-input-help/440378>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [January 13, 2021, 12:15pm UTC](https://forum.freecodecamp.org/t/create-a-controlled-input-help/440378 "2021-01-13T12:15:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andy7jacobs](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/andy7jacobs/32/134058_2.png) [@andy7jacobs](https://forum.freecodecamp.org/u/andy7jacobs)\
**Post date:** [January 13, 2021, 12:15pm UTC](https://forum.freecodecamp.org/t/create-a-controlled-input-help/440378/1 "2021-01-13T12:15:02Z")

</div>

**Tell us what’s happening:**  
Hello campers, I need help solving this Challenge, I´m stuck right now!

**Your code so far**

```jsx

class ControlledInput extends React.Component {
constructor(props) {
  super(props);
  this.state = {
    input: ''
  };
  // Change code below this line
handleChange(event) {
  this.setState({
    input: event.target.value
  });
}
  // Change code above this line
}
// Change code below this line
<input onChange = {this.handleChange.bind(this)}/>
// Change code above this line
render() {
  return (
    <div>
      { /* Change code below this line */}
<input value = {this.state.input}/>
      { /* Change code above this line */}
      <h4>Controlled Input:</h4>
      <p>{this.state.input}</p>
    </div>
  );
}
};

```

**Your browser information:**

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36`.

**Challenge:** Create a Controlled Input

**Link to the challenge:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/front-end-development-libraries/react/create-a-controlled-input)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![kevinSmith](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevinsmith/32/72934_2.png) [@kevinSmith](https://forum.freecodecamp.org/u/kevinSmith)\
**Post date:** [January 13, 2021, 2:51pm UTC](https://forum.freecodecamp.org/t/create-a-controlled-input-help/440378/2 "2021-01-13T14:51:58Z")

</div>

You’re almost there, it’s just that some things are in the wrong places.

So, the comments show three sections to makes changes.

In the first one (in the constructor) you have defined your _handleChange_ - but this is where it wants you to bind _this_. The format would be `this.myMethod = this.myMethod.bind(this);`

In the second one (in the class body) you have an `input` element - that doesn’t go there - that should be where you define your _handleChange_ method.

In the last comment section (in the JSX), you have your `input` element - good, that goes there. But it needs the _onChange_ attribute. In the other version of the `input`, you bind _this_. Yes, that works, but the more common way is to do this in the constructor to avoid clogging up the code. (Actually, with arrow functions, most people don’t even bother with this, but that’s cool for now.) So you would just need to pass the method.

When I make those changes, it works. And don’t get stressed - React is weird until you get used to it.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [July 15, 2021, 2:52am UTC](https://forum.freecodecamp.org/t/create-a-controlled-input-help/440378/3 "2021-07-15T02:52:01Z")

</div>

Closed on July 15, 2021, 2:52am UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
