Good evening,
I'm trying to pass an HTML input (a string) value as a JavaScript Function Parameter. I am pretty new to coding and recently started DOM Manipulation.
function lengthOfPassword (strLength) {
if (strLength.length >= 5) {
return true;
} else {
return false;
};
}
console.log(lengthOfPassword("l"));
This is the original function I wrote, and it performs as needed returning true or false depending on the length.
I have used the onclick="()" and document.getElementById("").value; to take the value from the HTML input and have it run in the function.
This is how far I have got:
<body>
<label for="password">Password:</label>
<input id="pwd" type="text" minlength="5" />
<button id="btn" onclick="lengthOfPassword()" type="button">Submit</button>
<script src="DOM.js"></script>
</body>
and my JS function now looks like this:
function lengthOfPassword() {
let strlength = document.getElementById("pwd").value;
if (strlength.length >= 5) {
return true;
} else {
return false;
};
}
I feel like I am tripping at the finish line! If someone could help explain where I have gone wrong, that would be great!
on*attributes. Use rather Element.addEventListener() right from your JS file or tag. - Roko C. Buljan