Nice work, we've got our set up form, and once we have the structure course, now it's deal with functionality
where in the context, yes, we have handle change function at the moment, we're just logging the event
object.
However, from the event object.
What I would want, I would want what is the name of the target, whether that is my mount or category
or difficulty.
And then also I'd want to get the value and we can do that by adding two variables or const and the
name is going to be equal to event target.
And by the way, keep on struggling with const.
And I'm going to go with Target here, and we're looking for a name.
So remember in the last video I mentioned probably 50 thousand times that names need to match and the
reason why we need to match, because in order to get those values, I'll use this name value.
And not only that, I also would want to get the value that is coming from the input.
So first, I would want to get the name so that I know, hey, this is the questions, input or category
or difficulty.
And then the second one will.
What is the actual value that is coming back on?
In order to get that, we go with event and then target and then value.
And if you want, of course, you can control it.
So let's go with name and value.
And you'll see once you navigate to the bigger screen that as you're changing these values.
So every time you type something in the input, you'll get back to things, you'll get the name of the
input and what is the value that is coming back.
Now, don't worry, of course, we're not changing anything.
As far as the you are yet noticed, it's still outstand because we haven't changed anything in a state
yet.
But it is a good start because I can say that I'm getting my difficulty input and then the value is
medium.
Now, how do we change the values in the state?
Well, I purposely set up everything as a object because the more input I would have and more, of course,
state values I would need to create and then separate functions and all that.
So in this case, I created everything as an object.
And I can simply use the fact that we can set object properties dynamically.
So what am I talking about here?
Well, I could go set quiz now, since it is an object, every time I change something about one of
the inputs, of course, I wouldn't want to wipe out the rest of the correct.
So I'm going to go down that not and I'll spread out the old values, the quiz, and then I'll dynamically
change the property and I'll pass in the name.
So remember, the target name has the name of my input.
Now that name matches exactly the proper names that I have here in the object, in a state value so
that I can dynamically change them and say change the property whose value is equal to nine, whether
that is a difficult category or amount.
And as far as the value know, I already have the value coming from the event that target value.
And what you'll notice right now if you navigate through the bigger screen, we have our provider notice
here.
I have a mountain category in sports and then every time I'll change this value, I notice how I'm dynamically
changing this.
So now, of course, amount is equal to one.
And then, for example, if I change the category to the history now, of course, my state value also
will change.
Now, don't worry about the fact that this is a strength, because remember, even though it was a no
input, once we get the value, it is coming back a string.
This is going to be the case where it doesn't affect our functionality.
Most importantly, remember, if you want to set up control inputs and you have quite a few of them,
it's a very good practice to set it up as an object and then use the fact that name value is going to
be equal to one of the properties.
Keep in mind, again, this comes back as amount category or difficulty.
And then I'm just saying, hey, get me all the values that I currently have in the object and then
get that property name, whatever it is, whether that is the difficulty category and questions.
And again, if you need to go back to my JavaScript Nugget series where I cover Dynamic Properties,
please do so because I'm not going to repeat that.
And when it comes to value, whatever we're getting back, whether or not it's 110 or different category
or different difficulty.
Hopefully that is clear and of course, we can deal with the handle submit.