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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:28:18+00:00 2026-05-22T11:28:18+00:00

My change function allows users to switch from country to country and get different

  • 0

My change function allows users to switch from country to country and get different text and features. It works when changing country selections. But at initial page load, it does not fire jQuery change to set the hide and show text divs for the default / initial country.

Both divs display at initial page load. When I change away and then back to the default/initial country, change fires, hide and show fire, and shows the proper information and features.

I have tried document.ready with a change function both inside the switch selections and outside the change function. Neither work – they don’t fire the hide, show and other jQuery in the switch cases at doc ready. Its not clear to me whether ‘ready’ is a valid trigger event.

I have also tried:

$('input[name=country]').value('US').trigger('click'); 

but it broke the change function. Here’s the code. The country selection below is just 2 countries to keep it simple, but actually, there are many.

$(document).ready(function()
{
//1st tier - select country via radio buttons:           
//Initialize country
$('input[name=country]:first').attr('checked', true);   //Set first radio button (United States)
//$('input[name=country]:first').attr('checked', true).trigger('ready');  //sets 1st button, but does not fire change
//$('input[name=country]:first').trigger('click'); //sets 1st button, but does not fire change

$('input[name=country]').change(function ()
{                                                                               
// change user instructions to be country specific
    switch ($('input[name=country]:checked').val())
    {
        case 'US':
        $('#stateMessage1').text('2. Select a state or territory of the United States.');
        $('#stateMessage2').text('Start typing a state of the United States, then click on it in the dropdown box.');
        $('#threeSelects').show();
        $('#twoSelects').hide();
        //select via 3 steps                        
        break;           
        case 'CA':
        $('#stateMessage1').text('2. Select a province or territory of Canada.');
        $('#stateMessage2').text('Start typing a province of Canada, then click on it in the dropdown box.');
        $('#twoSelects').show();
        $('#threeSelects').hide();
        //select town via 2 steps - country, town           
        break;         
    }
});
});
  • 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-22T11:28:19+00:00Added an answer on May 22, 2026 at 11:28 am

    Just chain .trigger('change') to the end of the handler assignment.

     // ----------v-------v-----quotation marks are mandatory
    $('input[name="country"]').change(function ()
    {                                                                               
    // change user instructions to be country specific
        switch ($('input[name="country"]:checked').val())
        {
            case 'US':
            $('#stateMessage1').text('2. Select a state or territory of the United States.');
            $('#stateMessage2').text('Start typing a state of the United States, then click on it in the dropdown box.');
            $('#threeSelects').show();
            $('#twoSelects').hide();
            //select via 3 steps                        
            break;           
            case 'CA':
            $('#stateMessage1').text('2. Select a province or territory of Canada.');
            $('#stateMessage2').text('Start typing a province of Canada, then click on it in the dropdown box.');
            $('#twoSelects').show();
            $('#threeSelects').hide();
            //select town via 2 steps - country, town           
            break;         
        }
    }).trigger('change');  // <--- RIGHT HERE
    

    Or if you only want it to fire on the first element, use triggerHandler() instead.

            // ...
            $('#twoSelects').show();
            $('#threeSelects').hide();
            //select town via 2 steps - country, town           
            break;         
        }
    }).triggerHandler('change');  // <--- RIGHT HERE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

change() function works and detects changes on form elements, but is there a way
If i do jQuery(expr).change( function), then I can get an event function to fire
I am making a website, and it allows users to change view options. I
I have a wxPython application which allows the users to select items from menus
I want to write a function that allows users to match data based on
After a call to the zooom function (which allows the user to interactively change
I have a page that allows users to dynamically change the loaded theme (stylesheet).
$('#types').change(function() { var htmlToAppend = <br/><input id='btnAddDictionary' type='button' value='Add Dictionary' />; if ($(#types).val() ==
I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
I have code as follows: $(#item_select).change(function() { var params = $(#item_select option:selected).val(); $.post('/account/ar_form.php', {idata:

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.