general que

Results 1 to 2 of 2

Thread: general que

  1. #1
    Join Date
    Dec 1969

    Default general que

    I have two dropdown list:<BR>A(Countries) and B(cities)<BR><BR>User selects a country in A...then B(cities) is populated with the appropriate cities.<BR><BR>When a city is selected, the form is submited to the same papge..where a query is done based on city value. Both dropdown list are refreshed. So no city is listed in B...only a list of countries in dropdown A<BR><BR>Problem: Currently the user has to Select a country again then a do another search..I would like to have the city dropdown to remain the user just changes the city..and if they want select a new this possible?<BR><BR>Here&#039;s the script that populates the dropdowns:<BR>&#060;script&#062;<BR>var tmp = location.pathname.split( "/" );<BR>var this_document = tmp[ tmp.length-1 ];<BR><BR>function Location () {<BR> this.addProvince = addLocationProvince;<BR>}<BR><BR>function addLocationProvince ( txt_province ) {<BR> this[ ] = txt_province;<BR>}<BR><BR>function txt_province ( province ) {<BR> = province;<BR> = province.replace( / /g, "_" );<BR> =;<BR> this.addCity = addProvinceCity;<BR>}<BR><BR>function addProvinceCity ( txt_city ) {<BR> this[ ] = txt_city;<BR>}<BR>function txt_city ( city ) {<BR> = city;<BR> = city.replace( / /g, "_" );<BR> = /./g, "" );<BR> =;<BR> return this;<BR>}<BR><BR>function setProvincesList() {<BR> <BR> var list = "";<BR> var sorted = new Array();<BR> <BR> for ( province in country ) {<BR> if ( province == "addProvince" ) { continue } <BR> sorted[ sorted.length ] = province;<BR> }<BR> <BR> sorted.sort();<BR> document.updateStoreInfo.txt_province.options[0] = new Option( "Select your province", "" );<BR> document.updateStoreInfo.txt_province.options[1] = new Option( "-----------------", "" );<BR> <BR> // clear the cities list if a new province was selected<BR> document.updateStoreInfo.txt_city.options.length = 2;<BR> var i = 2;<BR> for ( p in sorted ) { <BR> document.updateStoreInfo.txt_province.options[i] = new Option( country[sorted[p]].name, country[sorted[p]].id );<BR> i++;<BR> }<BR>}<BR><BR>function setCitiesList( province ) {<BR> <BR> var sorted = new Array(); <BR> var txt_province = eval( province );<BR> <BR> for ( city in txt_province ) {<BR> if ( city == "addCity" &#124&#124 city == "name" &#124&#124 city == "id" ) { continue }<BR> sorted[ sorted.length ] = city;<BR> }<BR> <BR> sorted.sort();<BR> document.updateStoreInfo.txt_city.options[0] = new Option( "Select your city", "" );<BR> document.updateStoreInfo.txt_city.options[1] = new Option( "---------------------", "" );<BR> <BR> var i = 2;<BR> for ( c in sorted ) { <BR> var selected = "";<BR> document.updateStoreInfo.txt_city.options[i] = new Option( txt_province[ sorted[c] ].name, txt_province[ sorted[c] ].id );<BR> i++;<BR> }<BR> document.updateStoreInfo.txt_city.options.length = i; <BR>}<BR>&#060;%= build_javascript_store_data() %&#062;<BR>&#060;/script&#062; <BR>

  2. #2
    Join Date
    Dec 1969

    Default Trivial...

    As you build the set of options, just compare the value of each option with what was selected on prior incarnation of the page and, if it matches, remember that index. Then, when the set of options is fully loaded up, set the selectedIndex of the &#060;SELECT&#062; to that index.<BR><BR>If you aren&#039;t using any ASP, then you&#039;ll have to parse the querystring in JS code, which is a pain but not too tough. If you are using ASP, then you&#039;ll just do<BR> var sel = document.updateStoreInfo.txt_province;<BR> var selix = 0;<BR> for ( p in sorted ) <BR> { <BR> var val = country[sorted[p]].id;<BR> sel.options[i] = new Option( country[sorted[p]].name, val );<BR> if ( val == &#039;&#060;%=Request("txt_province")%&#062;&#0 39; ) selix = ix;<BR> i++;<BR> }<BR> sel.selectedIndex = selix;<BR>}<BR><BR>I *have* to ask: Why do you name a &#060;SELECT&#062; field "[hl="yellow"]txt_[/hl]province"??? It&#039;s certainly *not* a text field.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts