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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:14:48+00:00 2026-06-05T20:14:48+00:00

I have the following very simple code snippet which is loaded from a separate

  • 0

I have the following very simple code snippet which is loaded from a separate file into one jQuery Mobile page in a multi-page site that I am building:

$(document).ready(function(){
    $('select[name="state_choice"]').change(function(){
        var thisState = $(this).val();
        var indexState = '#' + thisState;
        $('.state').hide();
            $(indexState).show();
      });
})

It was working but now it only works when I reload the page. I was examining the page load with Firebug and it was not consistently loading the jQuery file because this link was not showing up until reload.

<script src="inc/jquery/belmont.custom.js"></script>

Typically the console will show when a new page is called in jQuery mobile but I did find that this particular page did not always show up in the console log when a link to it was clicked. I have tested on a desktop simulator (Dashcode’s iOS Simulator), in desktop browsers (FF and Safari) and on my iPhone all with the same results.

Has anyone ever seen this behavior? How can I make sure that this works consistently?

EDIT: I have changed the code to use bind as follows:

$(document).bind('pageinit', function(){
    $('select[name="state_choice"]').change(function(){
        var thisState = $(this).val();
        var indexState = '#' + thisState;
        $('.state').hide();
        $(indexState).show();
    });
})

I have added console.log(indexState) to the function and this does not fire consistently either.

And I actually mis-spoke earlier – this is a mobile site consisting of single pages. Do I have to load the jQuery custom function script into every page? Or can I just load it into the one in question?

  • 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-05T20:14:49+00:00Added an answer on June 5, 2026 at 8:14 pm

    Here is how I got it sorted out. Since jQM loads each subsequent page with AJAX you need to treat interactions like this like any other dynamically loaded element. Changing bind() to on() (I am using jQuery 1.7+) gets everything working like it should:

    $('body').on('pageinit', '#id_of_page_using_function', function(){
        $('select[name="state_choice"]').change(function(){
            var thisState = $(this).val();
            var indexState = '#' + thisState;
            $('.state').hide();
            $(indexState).show();
        });
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following PHP code doing a very simple select into a table.
Very simple question: suppose I have the following js/jquery code doSomething(); $.get(url, callback); doSomethingElse();
Very simply put, I have the following code snippet: FILE* test = fopen(C:\\core.u, w);
I have got the following very simple code: function init() { var articleTabs =
I have the following very simple XML file and I want to quickly parse
I have the following very simple regex, which matches HTML tags in a string.
I have the very simple following code: main.cpp #include ui_library_browser.h #include <QtGui/QApplication> #include StartWindow.h
Trying to run a very simple flot.js example, I have the following code to
i have the following very simple code - int x=15000 int z=0.7*x cout<<z =
In Excel 2007 I have the following very simple code in VBA: Public Type

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.