Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!