Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140788

input data -> javascript and ternary operator! ty

$
0
0

I'm currently learning JavaScript and I had a few questions as to what was wrong with my code. I'm trying to make a simple age check with the ternary operator and form data. I'm trying to make it so that when the input from the form is under 18, you get the message, and when it is over the button appears. Thanks!

<html>
<head>
    <title>test</title>
    <script src="app.js" defer></script>
    <style>
    #continue {
        display: none;
    }
    </style>
</head>
<body>
    <form >
        <span>please enter your age</span>
        <input type="number" id="ageInput"/>
        <input type="submit">
    </form>
    <button id="continue">continue</button>
</body>
</html>

and here is my JS !

var userAge = document.getElementById("ageInput");
const continueButton = document.getElementById("continue");
function verification() {
    continueButton.style.display = (userAge.value >= 18) ? "block"
: "none";
}
 verification();
 console.log(continueButton.style.display);

Viewing all articles
Browse latest Browse all 140788

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>