Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7634255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:07:25+00:00 2026-05-31T07:07:25+00:00

I have following code in JavaScript function checkEntries() { if(document.getElementById(username)== && document.getElementById(password).value==) { alert(Please

  • 0

I have following code in JavaScript

function checkEntries()
{
    if(document.getElementById("username")=="" &&  document.getElementById("password").value=="")
    {
        alert("Please enter username and password");
    }
    if(document.getElementById("username").value=="")
    {
        alert("Please enter username");
    }
    if( document.getElementById("password").value=="")
    {
        alert("Please enter password");
    }
}

and HTML code as

<form name="LoginUser" method="post" action="LoginUser" onsubmit="checkEntries()">
              <table width="78%" height="90" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td width="47%" align="right" class="textstyle">Username:
                  <label for="username2"></label></td>
                <td width="53%" class="textstyle">
                  <input type="text" name="username" id="username" /><div id="testuser"></div>
                </td>
              </tr>
              <tr>
                <td align="right" class="textstyle">&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr id="passRow">
                <td align="right" class="textstyle">Password:</td>
                <td><label for="password"></label>
                  <input type="password" name="password" id="password"/>
Forgot Password?? Click here...               
<div id="testpwd"></div></td>
              </tr>
              <tr>
                <td align="right" class="textstyle">&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td align="right" class="textstyle">&nbsp;</td>
                <td><input type="checkbox" name="rempass" id="rempass" />
                  <span class="textstyle">Remember my password</span></td>
              </tr>
              <tr>
                <td align="right" class="textstyle">&nbsp;</td>
                <td class="textstyle">&nbsp;</td>
              </tr>
              <tr>
                <td align="right" class="textstyle">&nbsp;</td>
                <td class="textstyle">
                  <input type="submit" name="login" id="login" value="Sign in" />
                  </td>
              </tr>
            </table>
        </form>

The JavaScript code checks whether the username and password are entered on login form or not. It is working fine. But after showing error, it submits the form.

I want that this form should not be submitted if username and password are not entered. It should just stay on login page. How can I achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:07:26+00:00Added an answer on May 31, 2026 at 7:07 am

    Try:

    
    function checkEntries() {
       var errFlag = false;
       var errMsg = "";
        var username = document.getElementById("username");
        var password = document.getElementById("password")
       if(username == "") {
          errMsg += "Please enter username.\n";
          errFlag = true;
       }
       if(password == "") {
         errMsg += "Please enter password";
         errFlag = true;
       }
       if(!errFlag) {
          return true;
       }else {
          alert(errMsg);
          return false;
       }
    }
    
    

    And on your onsubmit:

    
    <form name="LoginUser" method="post" action="LoginUser" onsubmit="return checkEntries();">
    
    

    Hope it helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have the following JavaScript code: <script type=text/javascript> function clearRadioButtons() { document.getElementById(radiobutton1).checked=; //etc
I have the following Javascript code: function checkIfValid(){ var form = document.createuserform; if(form.fName.value ==
I have the following JavaScript code - function addOnClickEventHandler() { var userNameElement = document.getElementById(currentUser);
I have the following Javascript code add_num = { f: function(html, num) { alert(this.page);
I have the following code: <script type=text/javascript> $(document).ready(function() { $(#Save).click(function() { $.post(url, { data:
I have the following JavaScript code: (function() { function f(){ alert(1); } return f();
I have the following code: for (i=1; i<=len; i++) { var optcheck = col+'|'+document.getElementById('color').options[i].value;
I have the following Javascript code: function checkIfValid(){ var form = document.createuserform; var valid
Hello I have the following code: Javascript/jQuery: $(document).ready(function() { $(.clickMe).click(function() { $(.textBox).toggle(); }); });
I have the following code in Javascript: jQuery(document).ready(function(){ var actions = new Object(); var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.