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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:23:10+00:00 2026-05-24T19:23:10+00:00

I have this jQuery function for chained drop down boxes: function updateCargoDestinations() { $.ajax({

  • 0

I have this jQuery function for chained drop down boxes:

  function updateCargoDestinations() {
    $.ajax({
      url: "/truckingmanagement/account/getAccountUserCargoDestinations",
      data: "id=" + this.value,
      cache: false,
      success: function(html) {
        $("#cargoDestination").html(html);
      }
    });
  }
  $(document).ready(function() {$("#account").change(updateCargoDestinations);});

It works great, but I also need the function to run one time when the page loads so the chained drop down box will populate correctly. I have tried to set the context in the function like this:

context: ("#account")

but that is not working. How can I make it so this function runs one time when the page loads AND runs when the observed drop down box is changed?

  • 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-24T19:23:11+00:00Added an answer on May 24, 2026 at 7:23 pm

    Set this.value in a variable then check for undefined. If undefined set to whatever value it needs to initially populate the dropdown.

    function updateCargoDestinations() {
        var selectId = this.value;
        if (typeof selectId === "undefined") {
             selectId = "whatever_you_need_here"; 
        }
        $.ajax({
          url: "/truckingmanagement/account/getAccountUserCargoDestinations",
          data: "id=" + selectId,
          cache: false,
          success: function(html) {
            $("#cargoDestination").html(html);
          }
        });
    }
    
    
    $(document).ready(function() {
        updateCargoDestinations();
        $("#account").change(updateCargoDestinations);
    });
    

    Fiddle for undefined check: http://jsfiddle.net/kfJvA/1/

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

Sidebar

Related Questions

I have this jQuery code (function () { function load_page (pagename) { $.ajax({ url:
Hai this is my jquery function, function getRecordspage(curPage, pagSize) { $.ajax({ type: POST, url:
I have this jQuery function : $('a[name=pmRead]').click(function(e) { e.preventDefault(); $(this).parents(.pmMain).find(.pmMain5).toggle(); $.ajax({ type: 'POST', cache:
I have this jQuery which works fine $(li[id^='shop_id']).click( function () { alert(I clicked on
I have a jQuery selector, which has a chained function. Inside the function I
I have this jquery function function example(file, targetwidget, callback){ $(targetwidget).load(file, {limit: 25}, function(){ $(#widget_accordion).accordion({fillSpace:
I have this jQuery function function getData(jsonLink){ $(.scrollable .items).html(<img class='loadGif' src='/sites/all/themes/zen/journeyon/images/ajax-loader.gif' alt='' />); $.ajaxSetup({
I have this jQuery function: $(this).change(function(){ alert('I changed. ID: ' + $(this).attr(id)); }); I
i have this jQuery function: $(#text).load(test3.php?id=+ Math.random()); And this code is in page: user.php
i have this jquery function that i want to pass topic parameter to, i

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.