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 7893183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:04:00+00:00 2026-06-03T07:04:00+00:00

I have two textfields in HTML, when a button is clicked, I need to

  • 0

I have two textfields in HTML, when a button is clicked, I need to check that they are not empty.

but I have one working , my second one is not working,

here the code :

<!DOCTYPE html "> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
    <title>appLounge webService</title> 
    <link rel="stylesheet" type="text/css" media="all" href="css/reset.css" /> 
    <link rel="stylesheet" type="text/css" media="all" href="css/text.css" /> 
    <link rel="stylesheet" type="text/css" media="all" href="css/960.css" /> 
    <link rel="stylesheet" type="text/css" media="all" href="css/demo2.css" /> 

<script type='text/javascript'>
function notEmpty(login, password, helperMsg){
    if(login.value.length == 0){
        alert(helperMsg);
        login.focus();
        return false;
    }

    if(password.value.length == 0){
        alert(helperMsg);
        password.focus();
        return false;
    }

    return true;
}

</script>
</head> 



<body> 
<div class="container_12"> 

<!-- login data -->

    <div id="header" class="grid_12" style="background : url(img/login.png) no-repeat; background-size: 100%; height: 900px;" > 

<form>
        <div id="fieldLogin1">
            <input type="text" id='req1' name="userName" style="width:530px; height:44px" placeholder="UserName";  /><br />
        </div>
            <div class="clear">&nbsp;</div> 

        <div id="fieldLogin2">
             <input type="text" id='req2' name="password" style="width:530px; height:44px" placeholder="Password" />

        </div>
                    <div class="clear">&nbsp;</div> 

        <div id="checkBoxRememberMe">


                    <input  type="checkbox" name="remember" value="rememberYes" /> <br />

<form>

<input type='button' 
    onclick="notEmpty(document.getElementById('req1'), 'req2','Please Enter a Value')"
    value='Check Field' />
</form>

        </div>



    </div> <!-- end .grid_12 --> 
    <div class="clear">&nbsp;</div> 

</form>

</div> 
<!-- end .container_12 --> 
</body> 
</html> 

I have tried

onclick="notEmpty(document.getElementById('req1'), ('req2'),'Please Enter a Value')"

as well, but not working either, is this the problem?,

Thanks a lot!

  • 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-06-03T07:04:02+00:00Added an answer on June 3, 2026 at 7:04 am
    onclick="notEmpty(document.getElementById('req1'), 'req2','Please Enter a Value')"
    value='Check Field' />
    

    should actually be

    onclick="notEmpty(document.getElementById('req1'), document.getElementById('req2'),'Please Enter a Value')"
    value='Check Field' />
    

    EDIT (suggested by @dante):

    The following code can be more readable:

    onclick="notEmpty('req1', 'req2', 'Please Enter a Value')"
    value='Check Field' />
    

    and

    function notEmpty(loginId, passwordId, helperMsg) {
        var login = document.getElementById(loginId);
        if (!login.value.length) {
            alert(helperMsg);
            login.focus();
            return false;
        }
    
        var password = document.getElementById(passwordId);
        if (!password.value.length) {
            alert(helperMsg);
            password.focus();
            return false;
        }
    
        return true;
    }
    

    (On a sidenote, get used to using === rather than == whenever possible, so you don’t end up successfully (ahem…) comparing a boolean value to 0 one day. It is also a bit faster :))

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

Sidebar

Related Questions

I have two textfields and two buttons and the button should not be visible
In my iPad app I have two textfields. One displays the normal, default textfield
I have a form that has a group of 3 text_fields. I need two
I have a html form that is basically vertical but i really have no
I have two java classes. One is NewFrame.java where the forms(buttons, textfields) are located.
I have an HTML form with two input textfields. When the user tabs from
I have two g:textfields in the first one I should write a number lets
I currently have a html login page which has two textfields for e-mail address
I have a table which is being dynamically populated, each row contains two textfields
I have two <textField> one by one. Is possible to automatically stretch or shrink

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.