Target a Class within an Input field text box?

Hi I have a text box with an input field using the following HTML:

<input class="user-input" type="text" name="userAttempt" value="" >

I want to check the value entered by running the following when a submit button has been pressed:

var userAttempt = document.getElementsByClassName("user-input").value;
userAttempt = userAttempt.toLowerCase();

console.log("User Input was: " + userAttempt);

However this is returning an undefined variable.

Can anybody tell me where I am going wrong?

I have NO CLASS APPLIED within the property inspector, just within the input field HTML inside the text box.

Many thanks,

getElementsByClassName returns an Array

var userAttempt = document.getElementsByClassName("user-input")[0].value
userAttempt = userAttempt.toLowerCase();
console.log("User Input was: " + userAttempt)
1 Like

Thanks a million @MarkHunte usually an obvious answer! Next time ill look over the documentation first before posting…but thanks for the reply :beers: