Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

234
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda