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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:30:45+00:00 2026-06-04T00:30:45+00:00

What’s wrong in it why it’s not working… <script language=JavaScript type=text/javascript> //function to check

  • 0

What’s wrong in it why it’s not working…

 <script language="JavaScript" type="text/javascript">


//function to check empty fields

function isEmpty(strfield1, strfield2) {
  //change "field1, field2 and field3" to your field names

  strfield1 = document.forms[0].name.value 
  strfield2 = document.forms[0].email.value

  //name field

  if (strfield1 == "" || strfield1 == null || !isNaN(strfield1) || strfield1.charAt(0) == ' ') {
    alert( "Name is a mandatory field.\nPlease amend and retry.")
    return false;
  }

  //EMAIL field 
  if (strfield2 == "" || strfield2 == null || !isNaN(strfield2) || strfield2.charAt(0) == ' ') {
    alert(" Email is a mandatory field.\nPlease amend and retry.")
    return false;
  }
  return true;
}


//function to check valid email address

function isValidEmail(strEmail){
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  strEmail = document.forms[0].email.value;

 // search email text for regular exp matches

  if (strEmail.search(validRegExp) == -1)  {
    alert('A valid e-mail address is required.\nPlease amend and retry');
    return false;
  } 
  return true; 
}


//function that performs all functions, defined in the onsubmit event handler

function check(form)){
  if (isEmpty(form.field1)){
    if (isEmpty(form.field2)){
      if (isValidEmail(form.email)){
        return true;
      }
    }
  }
}
return false;
}

</script>

It doesn’t do anything I don’t understand what’s going there and in form I put this too

<form onsubmit="return check(this);" action="sendquery.php" name="contquery">
  • 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-04T00:30:47+00:00Added an answer on June 4, 2026 at 12:30 am

    First glance: too many brackets as shown by @FishBasketGordo so I will not repeat

    Second glance – you pass the field and do not test the field value

    Third glance: You do not pass the correct names to the function

    Fourth glance – isEmpty returns false when empty. It should return true

    I fixed all those

    DEMO HERE

    Complete page to show where what goes. Updated to do unobtrusive event handling on the form

    <html>
    <head>
    <title>Validation</title>
    <script type="text/javascript">
    
    // trim for IE
    if(typeof String.prototype.trim !== 'function') {
      String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g, '');
      }
    }
    
    //function to check empty fields
    
    function isEmpty(objfld) {
      var val = objfld.value;
      if (val.trim() == "" || val == null) {
        alert(objfld.name+" is a mandatory field.\nPlease amend and retry.");
        objfld.focus();
        return true;
      }
      return false;
    }
    
    //function to check valid email address
    
    function isValidEmail(objEmail){
      var validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
      var strEmail = objEmail.value;
      if (strEmail.match(validRegExp)) return true;
      alert('A valid e-mail address is required.\nPlease amend and retry');
      objEmail.focus();  
      return false;
    }
    
    //function that performs all functions, defined in the onsubmit event handler
    
    function validate(form) {
      if (isEmpty(form.name)) return false;
      if (isEmpty(form.email)) return false;
      return isValidEmail(form.email);
    }
    
    
    window.onload=function() {
      document.getElementById("form1").onsubmit=function() {
        return validate(this);
      }
    }
    
    </head>
    <body>
    <form id="form1">
      Name:<input type="text" name="name" /><br/>
      Email:<input type="text" name="email" /><br/>
      <input type="submit" />
    </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 a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.