Jump to content

confused with dropdown


solarisuser

Recommended Posts

Hi All,

 

I am using AJAX in a form so when someone enters a country, it populates the fields with the population, etc.  This works fine in text fields.

 

Then I am using a JS script that links two dropdown menus, so when you select "A" in the first dropdown, it does a mysql query and shows only the results relating to A in the second dropdown.  This works fine when clicking on it.

 

The problem: When I type in a country, AJAX fills in the first dropdown menu just fine.  However the second dropdown menu does not update.  When I click on the first dropdown menu, then it works.  I would like to know how can I make the second dropdown update when AJAX fills in the first dropdown.

 

Right now, I'm using onchange="update_second_dropdown();" on my first dropdown....  any suggestions would be a big help!  Thanks!

Link to comment
Share on other sites

I'm not sure how to do that =(

 

I'm using JSON syntax to return the results and fill in the fields.

 

Do I need to focus on using a function() that does something like ..

 

var field = document.getElementById('country').value;

if(field.length > 0) { document.getElementById('second_dropdown_id').update_second_dropdown(); }

 

?

Link to comment
Share on other sites

I don't know how you call your ajax, but here is how it should work

 


Ajax.request(....)
// function that parse the results

function ajax_return(txt){
    // do stuff with text (ajax return)
    // select first drop down
    update_second_dropdown(); 
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.