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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:32:25+00:00 2026-05-27T06:32:25+00:00

When I put the following code within the $(document).ready(function () {} it executes correctly.

  • 0

When I put the following code within the $(document).ready(function () {} it executes correctly.

                $('#welcome select').change(function () {
                var stateSelected = $('option:selected', this).val();

                setCookie('ia_state', stateSelected);

                switch (stateSelected) {
                    case 'Virginia':
                        window.location = '/Login/VA';
                        break;
                    case 'North Carolina':
                        window.location = '/Login/NC';
                        break;
                    case 'South Carolina':
                        window.location = '/Login/SC';
                        break;
                    default:
                        window.location = 'http://www.mysite.com/pages/login/login.html';
                }
            });

However, I need to place this code elsewhere on the page in order to make it easily accessible by the user.

I have placed the code by the select element that the user will have access to like so:

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


$('#welcome select').change(function () {
                var stateSelected = $('option:selected', this).val();

                setCookie('ia_state', stateSelected);

                switch (stateSelected) {
                    case 'Virginia':
                        window.location = '/Login/VA';
                        break;
                    case 'North Carolina':
                        window.location = '/Login/NC';
                        break;
                    case 'South Carolina':
                        window.location = '/Login/SC';
                        break;
                    default:
                        window.location = 'http://www.mysite.com/pages/login/login.html';
                }
            });




</script>
<div class="clear" id="welcome">
<p class="message">
    Welcome!</p>
<p class="switch-state">
    Switch State</p>
<select id="state-select" size="1"><option selected="selected" value="Virginia">VA</option><option value="North Carolina">NC</option><option value="South Carolina">SC</option><option value="Alabama">AL</option><option value="Alaska">AK</option><option value="Arizona">AZ</option><option value="Arkansas">AR</option><option value="California">CA</option><option value="Colorado">CO</option><option value="Connecticut">CT</option><option value="Delaware">DE</option><option value="Florida">FL</option><option value="Georgia">GA</option><option value="Hawaii">HI</option><option value="Idaho">ID</option><option value="Illinois">IL</option><option value="Indiana">IN</option><option value="Iowa">IA</option><option value="Kansas">KS</option><option value="Kentucky">KY</option><option value="Louisiana">LA</option><option value="Maine">ME</option><option value="Maryland">MD</option><option value="Massachusetts">MA</option><option value="Michigan">MI</option><option value="Minnesota">MN</option><option value="Mississippi">MS</option><option value="Missouri">MO</option><option value="Montana">MT</option><option value="Nebraska">NE</option><option value="Nevada">NV</option><option value="New Hampshire">NH</option><option value="New Jersey">NJ</option><option value="New Mexico">NM</option><option value="New York">NY</option><option value="North Dakota">ND</option><option value="Ohio">OH</option><option value="Oklahoma">OK</option><option value="Oregon">OR</option><option value="Pennsylvania">PA</option><option value="Rhode Island">RI</option><option value="South Dakota">SD</option><option value="Tennessee">TN</option><option value="Texas">TX</option><option value="Utah">UT</option><option value="Vermont">VT</option><option value="Washington">WA</option><option value="West Virginia">WV</option><option value="Wisconsin">WI</option><option value="Wyoming">WY</option><!-- 
                        <option value="North Carolina">NC</option>
                        <option selected="selected" value="Virginia">VA</option>
                     --></select></div>

However, this code does not run when value of the select element is changed on the page. What am I doing wrong?


Edit:

I have placed the javascript after the div element “welcome” and I also have it within a $(document).ready(function () {} function.

The function is now being hit the very first time the page loads. However, it is not being called when the value of the select element is changed. It is as if the event is not hooked up to the handler now.

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

    Put the script after the “welcome” <div>, not before it.

    Scripts are run when they’re “seen” by the HTML parser. Thus, your script runs before the “welcome” <div> is part of the DOM, so the selector comes up empty. If you put your script after it, however, it should work. (At least, the selector will find what it’s looking for.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following code, UIManager.put(JFrame.activeTitleBackground, Color.red); for change the toolbar color in
I have put together the following mootools script window.addEvent('domready', function() { var shouts =
Let's say I put the following code somewhere in a Master page in my
I have the following code which should put programs startable in Bash. if [
I have done the following code in JavaScript to put focus on the particular
I have the following code which works when i put it in any blank
Very simply put, I have the following code snippet: FILE* test = fopen(C:\\core.u, w);
The following code works for stretching the child Grid within the ListBoxItem in Silverlight
I expect following code to put my span to the top-left corner of the
The following line of code displays an image on my application window, within an

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.