Advertisement:

Author Topic: Drop-down selection for city at search  (Read 17820 times)

revelation

  • Newbie
  • *
  • Posts: 3
Re: Drop-down selection for city at search
« Reply #15 on: February 05, 2013, 09:37:33 pm »
Anyone figure out how to change 'ListAll' to something that will pull cities from select regions?

serjuc11111

  • Hero Member
  • *****
  • Posts: 814
Re: Drop-down selection for city at search
« Reply #16 on: February 06, 2013, 01:36:35 pm »
in what file u want to do that?main...search page...or inc.search?thx

kanum

  • Newbie
  • *
  • Posts: 20
Re: Drop-down selection for city at search
« Reply #17 on: February 07, 2013, 01:10:11 am »
in what file u want to do that?main...search page...or inc.search?thx

On Main File (on sidebar search).

Thanks

pinkfloyd69

  • Newbie
  • *
  • Posts: 6
Re: Drop-down selection for city at search
« Reply #18 on: February 10, 2013, 11:21:18 pm »
I have tehe same problem...

How Can I select only the cities when i select a region? When i select a region show all cities ;(

lemike

  • Newbie
  • *
  • Posts: 11
Re: Drop-down selection for city at search
« Reply #19 on: March 26, 2013, 04:10:57 am »
Bumping here... Has anybody figured out how to ::

1- Show dropdown menu for regions in the search sidebar
2- Show dropdown menu for cities dependent on the region dropdown selection

Just like the dropdowns for countries/regions/cities in item-post.php.

Thanks for your help!!

geo78

  • Full Member
  • ***
  • Posts: 100
Re: Drop-down selection for city at search
« Reply #20 on: March 31, 2013, 04:03:51 am »
Interested too to find a solution for this  8)

serjuc11111

  • Hero Member
  • *****
  • Posts: 814
Re: Drop-down selection for city at search
« Reply #21 on: April 23, 2013, 05:50:38 pm »
no solution for this?thx

jimmyconway

  • Newbie
  • *
  • Posts: 1
Re: Drop-down selection for city at search
« Reply #22 on: June 23, 2013, 01:49:55 am »
Hi, I am using a custom theme built on the modern default theme and was facing the same issue regarding displaying cities per region on the sidebar search engine.

Here is my solution:
All changes need to be done in search.php

First of all, add a region dropdown list in the "Location" section, you will end up with this code for that div:
Code: [Select]
                            <h3><strong><?php _e('Location''modern'); ?></strong></h3>
                            <div class="row one_input">
                                <h6><?php _e('Region''modern'); ?></h6>
                                <?php ItemForm::region_select(osc_get_regions(osc_user_country()), osc_user()); ?>
                                <h6><?php _e('City''modern'); ?></h6>
                                <select id="sCity" name="sCity">
                                    <option value="">Any City</option>
                                </select>
                                <input type="hidden" id="sRegion" name="sRegion" value="" />
                            </div>

Now, we are going to edit the javascript at the very bottom of the page:
Remove that autocomplete code:
Code: [Select]
                    $( "#sCity" ).autocomplete({
                        source: "<?php echo osc_base_url(true); ?>?page=ajax&action=location",
                        minLength: 2,
                        select: function( event, ui ) {
                            $("#sRegion").attr("value", ui.item.region);
                            log( ui.item ?
                                "<?php _e('Selected''modern'); ?>: " + ui.item.value + " aka " + ui.item.id :
                                "<?php _e('Nothing selected, input was''modern'); ?> " + this.value );
                        }
                    });

Replace it by the following:
Code: [Select]
                    $('#regionId').change(function updateCityList() {
                        var actualRegionId   = $(this).val();

                        if ( Math.floor(actualRegionId) == actualRegionId && $.isNumeric(actualRegionId)) {
                            /*Get cities per region*/
                            $.ajax({
                                url: "<?php echo osc_base_url(true); ?>?page=ajax&action=cities",
                                data: { regionId: actualRegionId },
                                success: function( cities, err){
                                    var $el = $("#sCity"),
                                        citiesOptions = {};
                                   
                                    $('#sCity option:gt(0)').remove();
                                    $el.val("");
                                    $el.prev("span").text("Any City");
                                    $.each(cities, function(key, value) {
                                      $el.append($("<option></option>")
                                         .attr("value", value.s_name).text(value.s_name));
                                    });
                                    $("#sRegion").attr("value", $("#regionId option[value='"+actualRegionId+"']").text());
                                },
                                dataType: "json"
                            });
                        }
                    });
Basically what it does, is an ajax request when the region is changed. We pass the regionId and we are returned with the different cities of the specified region. From there, we just need to replace everything in the dropdown with the new list of cities.

Hope that helps.
;)

shamim_biplob

  • Full Member
  • ***
  • Posts: 169
Re: Drop-down selection for city at search
« Reply #23 on: July 12, 2013, 09:51:41 pm »
i used this code and worked. but dont kno why after one day it is not working. i change nothing.  in city only showing drop down but no city.
please take a look.

http://www.banglardokan.com


please help me.

Nazar

  • Jr. Member
  • **
  • Posts: 75
Re: Drop-down selection for city at search
« Reply #24 on: July 20, 2013, 02:04:28 pm »

theklassifieds

  • Newbie
  • *
  • Posts: 3
Re: Drop-down selection for city at search
« Reply #25 on: August 23, 2015, 11:51:44 pm »
Hi, I am using a custom theme built on the modern default theme and was facing the same issue regarding displaying cities per region on the sidebar search engine.

Here is my solution:
All changes need to be done in search.php
.
.
.
Basically what it does, is an ajax request when the region is changed. We pass the regionId and we are returned with the different cities of the specified region. From there, we just need to replace everything in the dropdown with the new list of cities.

Hope that helps.
;)

This is brilliant!! Any chance I can get some code to have the chosen Region/City remain for the user's next search? At the moment it is being cleared after every search. Thanks

SmaRTeY

  • Osclass Hero
  • Hero Member
  • *
  • Posts: 2519
Re: Drop-down selection for city at search
« Reply #26 on: August 24, 2015, 02:16:25 am »
What search menu? The one on top in your header or the advanced search sidebar on search result page?

MissTS

  • Newbie
  • *
  • Posts: 32
Re: Drop-down selection for city at search
« Reply #27 on: September 10, 2015, 09:21:26 am »
my page has this...  not sure where to change it or if that is right for this template


    // meta tag robots
    if( osc_count_items() == 0 || stripos($_SERVER['REQUEST_URI'], 'search') ) {
        osc_add_hook('header','bender_black_nofollow_construct');
    } else {
        osc_add_hook('header','bender_black_follow_construct');
    }

    bender_black_add_body_class('search');
    $listClass = '';
    $buttonClass = '';
    if(osc_search_show_as() == 'gallery'){
          $listClass = 'listing-grid';
          $buttonClass = 'active';
    }
    osc_add_hook('before-main','sidebar');
    function sidebar(){
        osc_current_web_theme_path('search-sidebar.php');
    }
    osc_add_hook('footer','autocompleteCity');
    function autocompleteCity(){ ?>
    <script type="text/javascript">
    $(function() {
                    function log( message ) {
                        $( "<div/>" ).text( message ).prependTo( "#log" );
                        $( "#log" ).attr( "scrollTop", 0 );
                    }

                    $( "#sCity" ).autocomplete({
                        source: "<?php echo osc_base_url(true); ?>?page=ajax&action=location",
                        minLength: 2,
                        select: function( event, ui ) {
                            $("#sRegion").attr("value", ui.item.region);
                            log( ui.item ?
                                "<?php echo osc_esc_html( __('Selected', 'bender_black') ); ?>: " + ui.item.value + " aka " + ui.item.id :
                                "<?php echo osc_esc_html( __('Nothing selected, input was', 'bender_black') ); ?> " + this.value );
                        }
                    });
                });
    </script>

now sure where, what line to change from and to

Adyyda

  • Sr. Member
  • ****
  • Posts: 435
Re: Drop-down selection for city at search
« Reply #28 on: February 27, 2016, 07:37:20 pm »
Hi, I am using a custom theme built on the modern default theme and was facing the same issue regarding displaying cities per region on the sidebar search engine.

Here is my solution:
All changes need to be done in search.php

First of all, add a region dropdown list in the "Location" section, you will end up with this code for that div:
Code: [Select]
                            <h3><strong><?php _e('Location''modern'); ?></strong></h3>
                            <div class="row one_input">
                                <h6><?php _e('Region''modern'); ?></h6>
                                <?php ItemForm::region_select(osc_get_regions(osc_user_country()), osc_user()); ?>
                                <h6><?php _e('City''modern'); ?></h6>
                                <select id="sCity" name="sCity">
                                    <option value="">Any City</option>
                                </select>
                                <input type="hidden" id="sRegion" name="sRegion" value="" />
                            </div>

Now, we are going to edit the javascript at the very bottom of the page:
Remove that autocomplete code:
Code: [Select]
                    $( "#sCity" ).autocomplete({
                        source: "<?php echo osc_base_url(true); ?>?page=ajax&action=location",
                        minLength: 2,
                        select: function( event, ui ) {
                            $("#sRegion").attr("value", ui.item.region);
                            log( ui.item ?
                                "<?php _e('Selected''modern'); ?>: " + ui.item.value + " aka " + ui.item.id :
                                "<?php _e('Nothing selected, input was''modern'); ?> " + this.value );
                        }
                    });

Replace it by the following:
Code: [Select]
                    $('#regionId').change(function updateCityList() {
                        var actualRegionId   = $(this).val();

                        if ( Math.floor(actualRegionId) == actualRegionId && $.isNumeric(actualRegionId)) {
                            /*Get cities per region*/
                            $.ajax({
                                url: "<?php echo osc_base_url(true); ?>?page=ajax&action=cities",
                                data: { regionId: actualRegionId },
                                success: function( cities, err){
                                    var $el = $("#sCity"),
                                        citiesOptions = {};
                                   
                                    $('#sCity option:gt(0)').remove();
                                    $el.val("");
                                    $el.prev("span").text("Any City");
                                    $.each(cities, function(key, value) {
                                      $el.append($("<option></option>")
                                         .attr("value", value.s_name).text(value.s_name));
                                    });
                                    $("#sRegion").attr("value", $("#regionId option[value='"+actualRegionId+"']").text());
                                },
                                dataType: "json"
                            });
                        }
                    });
Basically what it does, is an ajax request when the region is changed. We pass the regionId and we are returned with the different cities of the specified region. From there, we just need to replace everything in the dropdown with the new list of cities.

Hope that helps.
;)


Hello. Your code works except 2 issues:
1. after you select region/city and you click on Apply, you get the proper results and olso, the selection you have made in sidebar (region/city) is gone. The values are not kept. How can we keep them until user resets the dropdowns?
2. when you perform a selection, the address of the new page looks like this /regionId,782154/city,Agrișu+Mare/region,Arad/ , so, we have the region twice, one time as id 782154 and once as region,Arad . It should show just 1 time, so how can we see just /city,Agrișu+Mare/region,Arad/ (lose regionId).
Thanks