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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:26:11+00:00 2026-05-15T06:26:11+00:00

Today, I started to code a page that prompts the user to choose their

  • 0

Today, I started to code a page that prompts the user to choose their PC specification, and the code is as follows.

<html>
    <title>Computer Specification Chooser</title>

    <head>
        <script type="text/javascript">
            var compSpec = document.compChooser;

            function processorUnavailable_onclick()
            {
                alert("Sorry, that processor speed is currently unavailable.");
                compSpec.processor[2].checked = true;
            }
        </script>
    </head>

    <body>
        <form name="compChooser">
            <p>Tick all components you want included in your computer</p>

            <p>
            DVD-ROM

            <input type="checkbox" name="chkDVD" value="DVD-ROM" />
            <br />

            CD-ROM
            <input type="checkbox" name="chkCD" value="CD-ROM" />
            <br />

            Zip Drive
            <input type="checkbox" name="chkZIP" value="ZIP DRIVE" />
            </p>

            <p>
            Select the processor speed you require
            <br />

            <input type="radio" name="processor" value="3.8" />
            3.8 GHz

            <input type="radio" name="processor" value="4.8" onclick="processorUnavailable_onclick()" />
            4.8 GHz


            <input type="radio" name="processor" value="6" />
            6 GHz
            </p>

            <input type="button" name="btnCheck" value="Check Form" />
        </form>
    </body>

</html>

The problem I’m facing is in the function that I’ve tied to the event handler. When I try to choose the radio button of the processor value 4.8 GHz, yes it alerts me with the message inside the function, but after that, it doesn’t not execute the next statement inside the function, that is, to check the next processor value, 6 GHz.

I’ve tried to change it and test on it, and found out when I set the var compSpec = document.compChooser as a local variable inside the function instead of a global variable, the next statement could be executed.

But I thought for a global variable, it is accessible everywhere on the page and also inside a function. But why now can’t I accesses it inside my function?

Besides, I stumbled upon a weird article while googling. It says that when a global variable is created, it is added to the window object. Why does this happen? And what are the benefits and uses of it?

  • 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-15T06:26:11+00:00Added an answer on May 15, 2026 at 6:26 am

    In JavaScript, a global variable is a property of the global object. When running inside a browser, the global object is the window object. So if you don’t use the var keyword, you are not actually declaring a variable, instead you are setting a property of the window object. It’s useful because the window object is accessible from everywhere, and so is your global variable.

    If you declare compSpec as a variable (var) inside your processorUnavailable_onclick function, its scope will be limited to that function (and closures created inside it). If you set compSpec as a global variable (i.e., a property of window), then it will be available from everywhere:

    function body_onload()
    {
        window.compSpec = document.compChooser;
    }
    
    function processorUnavailable_onclick()
    {
        alert("Sorry, that processor speed is currently unavailable.");
        window.compSpec.processor[2].checked = true;
    }
    
    ...<body onload="body_onload()">...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Finally, I find some article in http://code.google.com/intl/en/web/ajaxcrawling/docs/getting-started.html msnbc use this method. Thanks for all
I started coding with groovy today and I notices that if I take the
Today I received an email, which announced that a service will be migrated from
Today my question is how would I go about creating a view in a
Today I tried to download EGit plug-in from eclipse.org, and waited an hour and
Today I was looking the latest exam of the local informatics olympiad and I
Today at school the teacher asked us to implement a duplicate-deletion algorithm. It's not
Today i StumbleUpon a strange cache behavior of Firefox 4 which is described bellow.
Some of you may or may not (probably not) know about my framework .
I'm running Eclipse Helios Service Release 1, with Tomcat 7.0.12 in Linux Ubuntu Natty

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.