Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

236
Visualizações
Uncaught TypeError: Cannot read properties of undefined (reading 'uname') and also No debugger available, can not send 'variables'

Here I'm trying to execute the following code but it throws the above error in console log in website page, I am unable to identify the error .

I have coded this webpage in such a way that it should show an error like "enter the user name" and "enter the password" whenever the input boxes are left empty but instead of this it is showing an uncaught type error. Kindly help me to find the solution.

my github code link is:https://github.com/harish-123445/login-form-using-html-css-javascript

function vfun(){
            var uname=document.forms["myform"]["uname"].value;
            var pword=document.forms["myform"]["pword"].value;

        if(uname==null || uname=="" ){
                  document.getElementById("errorBox").innerHTML =
                   "enter the user name";
                 return false;
        }

        if(pword==null || pword==""){
                  document.getElementById("errorBox").innerHTML =
                   "enter the password";
                 return false;
        }

        if (uname != '' && pword != '' ){
         alert("Login successfully");
                         }

        }
<!DOCTYPE html>
<html >
<head>
<title>sign in form</title>
    <link rel="stylesheet" type="text/css" href="style.css">
    <script type="text/javascript" src="js.js"></script>  
<body>
        <div class="box">
        <img src="user.png" class="user">
            <h1 >LOGIN HERE</h1>

            <form class="myform" onsubmit= "return vfun()">
                
                <p>USERNAME </p>
                <input type="text" name="uname" placeholder="enter username" >

                <p>PASSWORD </p>
                <input type="password" name="pword" placeholder="enter password">
                
                <div id="errorBox"></div>
                <input type="submit" name="" value="login">

                <br><br>
                <a href="register.html" >Register for new user</a>
            </form>
        </div>

</body>
</head>
</html>

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I have edited your code. I have called your username and password using getElementById and your two error boxes with different id names and now it is working fine.

function vfun(){
            var uname=document.getElementById("name").value;
            var psword=document.getElementById("passw").value;

        if(uname==null || uname=="" ){
                  document.getElementById("errorBox2").innerHTML =
                   "enter the user name";
                 return false;
        }

        if(psword==null || psword==""){
                  document.getElementById("errorBox").innerHTML =
                   "enter the password";
                 return false;
        }

        if (uname != '' && pword != '' ){
         alert("Login successfully");
                         }

        }
<!DOCTYPE html>
<html >
<head>
<title>sign in form</title>
    <link rel="stylesheet" type="text/css" href="style.css">
    <script type="text/javascript" src="js.js"></script>  
<body>
        <div class="box">
        <img src="user.png" class="user">
            <h1 >LOGIN HERE</h1>

            <form class="myform" onsubmit= "return vfun()">
                
                <p>USERNAME </p>
                <input type="text" name="uname" id="name" 
 placeholder="enter username" >

  <div id="errorBox2"></div>

                <p>PASSWORD </p>
                <input type="password" name="pword" id="passw" 
            placeholder="enter password">

              
               
                
                <div id="errorBox"></div>
                <input type="submit" name="" value="login">

                <br><br>
                <a href="register.html" >Register for new user</a>
            </form>
        </div>

</body>
</head>
</html>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda