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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:38:02+00:00 2026-05-30T20:38:02+00:00

I am showing alerts if 3 textboxes or any single text box is empty

  • 0

I am showing alerts if 3 textboxes or any single text box is empty. For example:
if all are empty then alert will be" please fill up all"
else if 1st and 2nd text boxes are empty then alert will be "please fill up 1st and 2nd text box"
similarly if 1st and 3rd text boxes are empty then alert will be "please fill up 1st and 3rd text box"
similarly if 2nd and 3rd text boxes are empty then alert will be "please fill up 2nd and 3rd text box"
similarly if only 1st text box is empty then alert will be "please fill up 1st text box"
similarly if only 2nd text box is empty then alert will be "please fill up 2nd text box"
similarly if only 3rd text box is empty then alert will be "please fill up 3rd text box"

But problem is i have to write so many if-else statements in javascript if number of text boxes are 10 or more. Is their any solution for this to minimize the code and accordingly alert will come if any of the above condition satisfies?

I have written the if-else code individually but it is very lengthy like this:

 <form name="frm" action="confirmsubmit.jsp">
 <script type="text/javascript">
<!--
function confirmation() {
  var textboxname1=document.frm.textboxname1;
  var textboxname2=document.frm.textboxname2;
  var textboxname3=document.frm.textboxname3;

 //alert if all text boxes are empty

       if((textboxname1.value==null)||(textboxname1.value=="")&& (textboxname2.value=="")||(textboxname2.value==null)){
   alert("Please fill up first text box<br/>Please fill up second text box<br/>Please fill up 3rd text box");//alert for all
           textboxname1.focus();
           return false
       }

  //alert if 2nd text box is empty

         else if((textboxname2.value=="")||(textboxname2.value==null))
           {
 alert("Please Please fill up second text box");//alert for 2nd text box
           textboxname2.focus();
           return false 
           }              

   //alert if 3rd text box is empty   

         else if((textboxname3.value=="")||(textboxname3.value==null))
           {
 alert("Please Please fill up third text box");//alert for 3rd text box
           textboxname3.focus();
            return false 
           }  

          // similarly i have to show alert if 2nd and 3rd boxes are empty and so on, but is there any solution to minimize the code? 

            return true

   }
  //-->
  </script> 


<input type="text" name="textboxname1"/>
<input type="text" name="textboxname2"/>
<input type="text" name="textboxname3"/>
<input type="submit" onclick="return confirmation()"/> 
 </form>
  • 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-30T20:38:03+00:00Added an answer on May 30, 2026 at 8:38 pm

    to check every empty checkbox use this simple jquery selector:

    jQuery('input.test').not('[value]').each(function() {
        var blankInput = jQuery(this);
        //do what you want with your input
    });
    

    your js will be like this:

    function confirmation(domForm) {
        var jForm = jQuery(domForm);
        var values = jForm.find('.check').serializeArray();
    
        var failedFields = [];
        for(var i = 0; i < values.length; i++) {
            var o = values[i];
            if(o.value == null || o.value.length == 0) {
                failedFields.push(o.name);
            }
        }
    
        if(failedFields.length > 0) {
            var message = ''; 
            if(failedFields.length == values.length) {
                message = 'fill all fields please';
            }
            else {
                message = 'please fill the fields:';
                for(var i = 0; i < failedFields.length; i++) {
                    message += "\n";
                    message += failedFields[i];
                    }
            }
    
            alert(message);
            return false;
        }
    
        return true;
    }
    

    call confirmation on your onsubmit! like this:

    <form name="frm" onsubmit="return confirmation(this)" action="confirmsubmit.jsp">
        <input type="text" name="textboxname1" class="check"/>
        <input type="text" name="textboxname2" class="check"/>
        <input type="text" name="textboxname3"/>
        <input type="submit"/> 
     </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm showing a confirmation alert box through JavaScript: function checked() { if (hdnval.toLowerCase() !=
I have a form with a text box: wherever value changed by typing, showing
I want to display script errors in a popup alert instead of showing them
I have a question about showing an alert on the screen. The thing is:
I am showing an alert on UILongPressGestureRecognizer, the issue I am facing is that
I am creating a web user control for showing Alert on AspxGridView Columns(Delete/Edit) click
I am showing my alert dialog in a separate thread and its not working
The JavaScript alert box is appearing without close mark on top right side nor
My app only calls for alerts, but badges are showing up and won't clear.
Possible Duplicate: Prevent Back button from showing POST confirmation alert I have used the

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.