capture input text javascript value

Asked

Viewed 79 times

2

So you guys I’m studying oop in javascript to crawling still, for this I’m trying to add on my site elements dynamically through js

I am wanting to capture the value of my text field and when I click the add button the element is created follows the code created in jsfiddle

https://jsfiddle.net/fernandorrn/ensdt17m/

1 answer

4


The mistake you made was getting the value of input right in the class constructor. As the class is called right at the top of the page, this.add will always be an empty value. What you need to do is get the value of input whenever it is clicked on button.

See how it looks: https://jsfiddle.net/ensdt17m/1/

  • thanks guy more n have as I capture the input value directly from the builder?

  • Yes, but if you want a value always updated with whatever is in the input, you will have to get it every time you click the button.

  • @Fernandoalcantara what you can do is pass the element in the constructor, it would look like this: https://jsfiddle.net/ensdt17m/2/

  • vlw rafael helped me understand a little more the concept of object orientation, n knew that the builder could return a methods

Browser other questions tagged

You are not signed in. Login or sign up in order to post.