Jump to content

How Do I Dynamically Set The Selected Index Of A Dropdown?


kathymack

Recommended Posts

Hi

 

I am using a combination of javascript and php.

 

I use javascript to populate the country dropdown. For example if you selected united states, there is a state_prov dropdown list which updates to display a list of states, if you select Canada, the state_prov is populated with provinces and you select Australia, the state_prov dropdown list is hidden.

 

This works great, except when the record is being added to a table, but when I have the modify form displaying I can't set the selectedIndex of the state_prov to the stateprov value I retreive from the table.

 

Is there some Javascript code I can use to do this?

 

I have renamed my functions.js to functions.txt so that it can be uploaded here.

modify.php

functions.txt

Here's an example of this I've already done for someone.

http://forums.phpfreaks.com/topic/270342-after-picking-us-or-canada-have-the-appropriate-states-or-provinces-show/

 

In the lower $.each, you could just do an if statement for the state of choice and set the selected attribute when you add the one you want.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.