Link to home
Start Free TrialLog in
Avatar of astro26
astro26

asked on

related selects, how to get second select to display (not using cftwoselects)

I need code for two select boxes which are related...
ie one select changes the values in the second select...

however I have two problems....
1) this is an update page, and I need both selects to be filled out on update

2) I have searched this forum but could not find the answer

3) I cannot use cftwoselects (no custom tags)...


I have sucessfully found code and populated two dynamic selects (both as javascript array, and using javascript case statement {seemed to run much faster than arrays}),,,,,

however,
I do not know how to autopopulate the second select box with the previously selected value (and list other options related to the first select)...

ie,
us_States
ca,va,tx

us_cities
ventura,sacremento, arlington, richmond, arlington, dallas, san antonio

I can select a state and only the cities are listed, but when I save the data (stateid, cityid) and return to the page with these values I get .... the state populated and displaying the previously selected state, but the city select is blank...

can anyone help and give code examples?
SOLUTION
Avatar of jyokum
jyokum
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of astro26
astro26

ASKER

thanks both for the quick response.... they both are very close to what I want....

I guess what I really need is....

the above page is test.cfm


can both select boxes be populated when the url is

test.cfm?categoryid=2&assortmentid=5

I can't get the second box to show the correct text...

can this be done by somehow rerunning the function? then somehow selecting the selected index of the second select box?

test.cfm?group=B&item=5 ???

I am using coldfusion, and somehow need to populate the second select with all values given the first select value passed, and make the second select show the value passed in as well.  I hope this makes sense...

select 1
ladies
mens
childrens
sports

select 2
ladies
mens
childrens (selected)
hardliners

Ok, I looked at my post and it was not clearn, sorry about that...
step one, I come to the form and make my choices,
step two, I click a save button
setp three, I come back to the form and want to see what I chose (called from database)

I do not know how to in step three to make the second select box display all choices for my 1st select, and make the selected choice (the one highlighted) the one I chose in step 1.

Thanks again for your help both...
yes both the select boxes can be populated by using ur CFCODE

run a loop & populate teh select boxes based on the ID's passed to the form
& shhow the corresponding ID as selected

now as soon as the user chnages his option from the first selct box - the javascript will result in repopulating the 2nd select box based on the value selected.

that shld do it

let me know

K'Rgds
Anand
Avatar of astro26

ASKER

I am not sure what you mean?  

do you mean I make a couple of new queries and only run them if url.categoryid is defined?

<cfif isdefined(url.categoryid)>
<cfquery listallcategories>
  select * from category
</cfquery>

<cfquery listallassortmentsgivencategory>
  select * from assortment
  where categoryid = #url.categoryid#
</cfquery>
</cfif>

<cfif isdefined(selectid1)>
 <cfloop query=listallcategories>
     <option value="categoryid" <cfif id eq url.categoryid> selected </cfif>>#categorytext#</option>
 </cfloop>
</cfif>


<cfif isdefined(selectid2)>
 <cfloop query=listallassortmentsgivencategory>
     <option value="assortmentid" <cfif id eq url.assortmentid> selected </cfif>>#assortmenttext#</option>
 </cfloop>
</cfif>

I did not do correct syntax for brevities sake..
yeah cos i believe when ur in a edit mode the ID's will be defined & u cld just use them to populate ur values in the Drop down dor the first time

once there - then javascript will mamage whatever changes the user makes to the selection

right ?
Avatar of astro26

ASKER

i guess i overlooked the obvious... I thought that somehow I had to pass those id's to the javascript function which would then fire if those id's were present and repopulate those boxes, also.  a new function would fire to make the id's passed become the selected indexes....

I had no idea where to begin to make that happen...

thanks,
astro
if that for some odd reason doesn't work, let us know...
so is the issue solved ???

let me know incase u need more help !

Cheers
Anand
Avatar of astro26

ASKER

sorry took so long to respond, I was on a cruise.

Thanks, jyokum (I used your code for troubleshooting my selected index)...

Thanks anand, I used your code.

Thanks both for your patience until I awarded points.