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

  • Home
  • SEARCH
  • 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 6682877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:45:24+00:00 2026-05-26T04:45:24+00:00

I am new to Javascript. Recently I am trying to prepare a checkform function,

  • 0

I am new to Javascript. Recently I am trying to prepare a checkform function, although the function works, IE mentioned the “msg2” at the end was not declared, may experts please teach me how to make it work? Thanks a lot!

function check_si_form_info(form,mark,edit){
     if(mark==11 || mark=="all"){
            if(form.login.value==""){
                si_check_login.innerHTML="Please enter Login Name!";
                si_check_login.style.height="auto";
                form.login.style.backgroundColor="#FFD5FF";
                return false;
            }else if (form.login.value!==""){ 
            var loginname = form.login.value;
            xmlhttp=new XMLHttpRequest();
            xmlhttp.open('get','si/check_si_loginname.php?loginname='+loginname,true);
            xmlhttp.onreadystatechange = function(){
                if(xmlhttp.readyState == 4){
                    if(xmlhttp.status == 200){
                        msg2 = xmlhttp.responseText;
                        if(msg2 == '2'){
                        si_check_login.innerHTML="Login name is not available!";
                        si_check_login.style.height="auto";
                        form.login.style.backgroundColor="#FFD5FF";
                        return false;
                        }else if(msg2 == '1'){
                        si_check_login.innerHTML="";
                        si_check_login.style.height="0px";
                        form.login.style.backgroundColor="#FFFFFF";
                        }
                    }//200
                }//4            
            }//onreadystatechange
            xmlhttp.send(null);
            }
            if (msg2 == '2'){
            return false;
            }
    }//11
   }
  • 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-26T04:45:24+00:00Added an answer on May 26, 2026 at 4:45 am

    To declare a variable, add var msg2; at the beginning of your Currently, when your end of the function’s body has reached, msg2 is not yet defined. Also, you should declare all variables (xmlhttp) using var, unless you want them to leak to the global scope.

    A variable can be defined in some ways:

    • var msg2; inside the function: This DECLARES a private variable, and initialised it at undefined
    • var msg2; outside the function: Declares a variable. Private if the inner function is contained within another scope, eg function outer(){var msg2;function inner(){...}}. Public otherwise.
    • msg2=null; anywhere: This ASSIGNS null to variable msg2. If it has been defined already, see the previous line. Else, it will be publicly defined.

    Consider your code:

    function check_si_form_info(form,mark,edit){
         var msg2;// <-- Declare a variable
         if(mark==11 || mark=="all"){
                if(form.login.value==""){
                   ...
                    return false;
                }else if (form.login.value!==""){ 
                var loginname = form.login.value;
                xmlhttp=new XMLHttpRequest();
                xmlhttp.open('get','si/check_si_loginname.php?loginname='+loginname,true);
                xmlhttp.onreadystatechange = function(){
                    if(xmlhttp.readyState == 4){
                        if(xmlhttp.status == 200){
                            msg2 = xmlhttp.responseText;
                            if(msg2 == '2'){
                                ...
                                form.login.style.backgroundColor="#FFD5FF";
                                return false; // <--- false isn't received by any func
                            }else if(msg2 == '1'){
                                ...
                            }
                        }//200
                    }//4            
                }//onreadystatechange
                xmlhttp.send(null);
                }
                if (msg2 == '2'){ //<---This condition is always false
                    return false;
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently transferred a site to a new host. Reloaded everything, and the javascript
I've recently written a javascript RegExp to cleanse my data at the front end,
Recently a new framework for Javascript unit testing has been released. HERE Can anyone
I recently stumbled upon the Object.create() method in JavaScript, and am trying to deduce
Quite recently I read about JavaScript call usage in MDC https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/call one linke of
I've recently read that embedding ruby inside JavaScript is not a good idea. However,
New to javascript/jquery and having a hard time with using this or $(this) to
New to javascript, but I'm sure this is easy. Unfortunately, most of the google
im new to javascript and am intersted in creating a small o3d script: <!DOCTYPE
I'm relatively new to Javascript and was wondering if there's a quick way to

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.