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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:51:44+00:00 2026-05-13T08:51:44+00:00

I have a select box object and an ajax function is called OnChange using

  • 0

I have a select box object and an ajax function is called OnChange using the selected value as an input. I also want to call the the same function when the select box is first loaded. I use jQuery .load, but the ajax function is called before any of the options are loaded and the input to my ajax function is undefined. Does anyone know how to get jQuery to wait for all the options to load before calling the function?

Thanks.

Edit – Adding Code
I have found that a setTimeout() works pretty well to delay the function. However, I get nervous using setTimeout() because if the page loads slower than usual, it won’t work. I tried replacing the timeout with $(document).ready as you suggested, but the function was still called before an option was selected and the input was undefined.

Here’s the code:

<script type="text/JavaScript">    
    setTimeout('AjaxFunction($("#SelectID option:selected").val()));', 400);
</script>

<select id="SelectID" name="SelectName" onchange="AjaxFunction(this.value);">
<option value='Inland Empire'>Inland Empire</option>
<option value='San Bernardino'>San Bernardino</option>  
<option value='Riverside'>Riverside</option>
<option value='California'>California</option>  
</select>
  • 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-13T08:51:45+00:00Added an answer on May 13, 2026 at 8:51 am

    You should consider removing the onchange= and using one of the below methods to bind the event / execute it:

    <select id="SelectID" name="SelectName">
      <option value='Inland Empire'>Inland Empire</option>
      <option value='San Bernardino'>San Bernardino</option>  
      <option value='Riverside'>Riverside</option>
      <option value='California'>California</option>  
    </select>
    
    <script type="text/JavaScript">
        // placing the script after the select SHOULD ensure it executes after the 
        // select has been created
        $("#SelectID").change(function() {  // bind a change event:
          AjaxFunction($(this).val());
        }).change(); // and trigger a "change" event immediately
    
        // If you are using .load to bring #SelectID into existence, 
        // it would be much better to put the whole segment into the callback of
        // .load() as suggested by gaby
    
        $("#sometarget").load("/some-url-with-select-box", function() {
          // bind and trigger change event (alternate forms)
          $("#SelectID").bind('change', function() {
            AjaxFunction($(this).val());
          }).trigger('change');    
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a select box that needs to submit it's value to a server
I am using chosen.js ( http://harvesthq.github.com/chosen/ ) and I have a select box that
I Have a select box, on selectinga value in it I have to display
I have a form with a select box and three text input boxes. When
I have a Javascript function for my select box, but after I included runat=server
I am using jQuery; I have a select box the options of which are
I have a select box that is being populated dynamically from a database. As
I have a select box on a page that does a post with jQuery
I have a select box which has more than 200 items. Below the select
I have a select box on a classic ASP page which looks like this:

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.