JAVASCRIPT

Source Code Validasi Javascript Sederhana
<html>
<head>
<title>Validasi Javascript</title>        
</head>

<body>
<form method="post">
    <label for="username">Username : </label>
    <input type="text" id="username">
    <button type="submit">Kirim</button>
    </form> 
    
    
    <script>
    let input_text = document.getElementById('username');
    let btn = document.getElementsByTagName('button')[0];
        
    btn.addEventListener('click', function(e){
       if(input_text.value == ""){
           alert('Maaf username harus di isi!');
           e.preventDefault()
       } 
    }); 
    </script>
</body>
</html>