Link to home
Start Free TrialLog in
Avatar of lulu50
lulu50Flag for United States of America

asked on

Dropdown box

Hi,

I have three dropdown boxes

First is the State
Second is the City
Third is the Churches

What I want is if the user select state, City and churches than click on Search button.
the State dropdown box should select what the user submitted. the same
with the City and Churches.

right now the state works fine if I select Alabama and click on search the page refresh and
the selected State Alabama is selected and the rest of the states are displayed.

I want the city and churches to work just like the state.  I got the state to work because it is populated in coldfusion but the city and churches are populated thru Javascript that means I am lost here.

Please, see my HTML document.

Thank you.
test.html
Avatar of Sudhindra A N
Sudhindra A N
Flag of India image

Add this at the top of the page...
<cfoutput>
  <cfset cityList='1,1,Abbeville,22,2598,Sterling Heights,22,2599,Detroit,22,2600,Troy,22,2601,Nov' />
  <cfset churchList='1,1,Saint John Ame Church,1,2,First Assembly of God,1,3,Bethlehem Baptist Church,1,4,Calvary Baptist Church,1,5,Christ Temple Baptist Church,1,6,First Baptist Church,1,7,Judson Baptist Association,1,8,Mary Magdalene Baptist Church,1,9,Mount Olive Baptist Church,1,10,New Hope Freewill Baptist Church,1,11,New Mount Zion Free Will Baptist Church,1,12,Rocky Mountain Baptist Church,1,13,Saint Peter Baptist Church,1,14,Sardis Baptist Church,1,15,Lakeside Christian Fellowship Church,1,16,Abbeville Church of Christ,1,17,Abbeville Memorial Church of God,1,18,Church of God in Christ,1,19,New Birth Holiness Church,1,20,New Testament Holiness Church,1,21,Jackson Chapel Church,1,22,Outreach for Souls Church,1,23,Abbeville United Methodist Church,1,24,Clopton United Methodist Church Parsonage,2598,344,Church1_Sterling,2599,345,Church1_Detroit,2600,346,Church1_Troy,2601,347,Church1_Novi' />
  
  <cfset selectedState=1 />
  <cfset selectedCity=0 />
  
  <cfif isdefined("form.DispStateBox")>
      <cfset selectedState=form.DispStateBox />
  </cfif>
  
  <cfif isdefined("form.GetCity")>
    <cfset selectedCity=form.GetCity>
  </cfif>
 </cfoutput>

Open in new window


Dropdown for City should be
<select name="GetCity" width="150" style="width: 150px" size="1"

 onChange="setOptionsCH(this.options[this.selectedIndex].value);"/>
 
                <cfoutput>
                <cfif selectedState neq "">
                  <option value="0" selected="selected">Select The City...</option>
                  <cfloop from="1" to="#listlen(cityList)#" index="i" step="3">
                    <cfif listgetat(cityList,i) eq selectedState>
                      <option value="#listgetat(cityList,i+1)#" <cfif selectedCity eq listgetat(cityList,i+1)>selected="selected"</cfif>>#listgetat(cityList,i+2)#</option>
                    </cfif>
                  </cfloop>
                </cfif>
                </cfoutput>

 									

 									</select>

Open in new window


Multiple select for church should be
<select name="GetChurch" style="width: 300px; height: 170px;" size="1" multiple>
                                           
                                           <cfoutput>
                                            <cfif selectedCity neq 0>
                                              <cfloop from="1" to="#listlen(churchList)#" index="i" step="3">
                                                <cfif listgetat(churchList,i) eq selectedCity>
                                                  <option value="#listgetat(churchList,i+1)#">#listgetat(churchList,i+2)#</option>
                                                </cfif>
                                              </cfloop>
                                            </cfif>
                                           </cfoutput>
                                           
                                           </select>

Open in new window

 

Update your code and let me know in case of any help needed. you can remove javascript list and assign the coldfusion list to the javascript variable, like

<cfoutput>
var getmyChurchList=#churchList#;
</cfoutput>

same for city list.

But these city and church list should be kept in the database for the ease of maintainance. If you need to add a city or a church then you have to update the cfm file again and again.
Avatar of lulu50

ASKER

ansudhindra

thank you for helping me.  It works great except one little thing is that in the Getchurch multiple selections.
I want when the user highlight the selections and click on search I want the page to refresh and select
what the user previously selected.

thank you so much
Avatar of lulu50

ASKER

right now I do see the list of the previous selections in the Getchurch and that is great I just want them to be highlighted.
Avatar of lulu50

ASKER

For testing when I select Alabama --> Abbeville --->
and selected only few churches from the church list
like:
Saint John Ame Church
First Assembly of God
Bethlehem Baptist Church

then clicked on Search
I got back all the churches from Abbeville but I just want instead to see only the selected churches highlighted.

I don't want to see all churches from Abbeville but I only want to see
Saint John Ame Church
First Assembly of God
Bethlehem Baptist Church

highlighted
Avatar of lulu50

ASKER

I am sorry I need to reword this.

"I don't want to see all churches from Abbeville but I only want to see
Saint John Ame Church
First Assembly of God
Bethlehem Baptist Church

highlighted "

I do want to see all churches back that are from Abbeville but I want what the user selected previously is to be highlighted.

Sorry, if I confused you.

ASKER CERTIFIED SOLUTION
Avatar of Sudhindra A N
Sudhindra A N
Flag of India 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
Avatar of lulu50

ASKER

ansudhindra

This is excellenttooooo  !!!!!!!!!!!!!!!!!!!!!!

Thank you and thank you and thank you
it is exactly how I want it beautiful

Thank you for one million and one !!!!!!!!!!
Avatar of lulu50

ASKER

Great Job!!!!!
Thank you again and again that's it I need to save some for my next question :)
You are welcome.......