Skip to content
Advertisement

How to get value from an input field from a class of input fields?

I wrote a code that contains several input fields of number type. They all have the same class and can have different values. But when I want to get a value from one of the input fields, the console log returns an undefined. Why’s that happening, and how to resolve this issue?

Code:

JS

JavaScript

CSS

JavaScript

HTML

JavaScript

Advertisement

Answer

var quantity = document.querySelectorAll('.quantity'); is not contain a single value. so you cannot change the value using .value it is like an array so you have to us indexing.

JavaScript

Output

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement