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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:14:19+00:00 2026-05-15T16:14:19+00:00

I have this form with a JS function to verify that there are no

  • 0

I have this form with a JS function to verify that there are no blank fields,
but it doesn’t work.

<head>
  <script language='javascript'>
      function verifyForm(){
        var msg='';
        if(document.getElementById('field1').value==''){msg+='Field 1  \n';}
        if(document.getElementById('field2').value==''){msg+='Field 2  \n';}
        if(msg!=''){
            alert('The following entries are empty:\n\n'+msg);
            return false
        }else{
            return true }
        }
  </script>
</head>

<body>
   <form name="frmRequest2" id="frmRequest2" action="<? echo $submitURL2; ?>" method="post" onsubmit='return verifyForm();'>
   Please answer all questions and enter "NONE" where appropriate.

  <table>
    <tbody>
      <tr>
        <th>List any items you already have</th>
        <th>List any items you need to get</th>
      </tr>
      <tr>
        <td><textarea name="field1" id="field1" rows="2" cols="39"> <? echo $field1; ?> </textarea></td>
        <td><textarea name="field2" id="field2" rows="2" cols="39"> <? echo $field2; ?> </textarea></td>
      </tr>

      <tr>
        <td colspan="4" align="center" valign="top" style="border-width: 0px 0px 0px 0px;"> <br />
        <input name="submit" value="Submit Data" type="submit"/> </td>
      </tr>      
    </tbody>
  </table>
  </form>
</body>
  • 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-15T16:14:20+00:00Added an answer on May 15, 2026 at 4:14 pm

    You have extra closing curly braces (}) after your if clauses.

    Edited to add: The following code works as expected and ignores any leading/trailing whitespace in the fields:

    <html>
    
    <head>
      <script language='javascript'>
          function verifyForm(){
            var msg='';
            if(document.getElementById('field1').value.replace(/\s+$|^\s+/, '') == '') {msg+='Field 1  \n';}
            if(document.getElementById('field2').value.replace(/\s+$|^\s+/, '') == '') {msg+='Field 2  \n';}
            if(msg!=''){
                alert('The following entries are empty:\n\n'+msg);
                return false;
            }else{
                return true;
            }
          }
      </script>
    </head>
    
    <body>
       <form name="frmRequest2" id="frmRequest2" action="" method="post" onsubmit='return verifyForm();'>
       Please answer all questions and enter "NONE" where appropriate.
    
       <table>
          <tbody>
          <tr>
            <th>List any items you already have</th>
            <th>List any items you need to get</th>
          </tr>
          <tr>
            <td><textarea name="field1" id="field1" rows="2" cols="39"></textarea></td>
            <td><textarea name="field2" id="field2" rows="2" cols="39"></textarea></td>
          </tr>
    
          <tr>
            <td colspan="4" align="center" valign="top" style="border-width: 0px 0px 0px 0px;">
              <input name="submit" value="Submit Data" type="submit"/>
            </td>
          </tr>
        </tbody>
      </table>
    
     </form>
    </body>
    
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this function to edit all fields that come from the form and
i have this function in jquery that verify if ALL the fields have at
I have a Profile form that inherits from sfGuardRegisterForm I have these fields: $this->useFields(
Hello i have this form filling javascript: function onLine(code,nn) { document.writeform.bericht.value+=code; document.writeform.bericht.focus(); document.writeform.nickname.value+=nn; write1();
I have this form submit code: Event.observe(window, 'load', init, false); function init() { Event.observe('addressForm',
I have this Form I am trying to upload my image but every time
I have this form inside a table: <table id=fields> <form method=post id=accountform></form> <tbody><tr><td class=key>First
I have a form validation script that is unfortunately returning the Stack overflow at
I have this code that I run when a user submits a form (this
I have this form: $form = array( '<form name=backup-form class=backup-form method=post action=#>', '<fieldset class=backup-fields>',

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.