Page 1 of 5 123 ... LastLast
Results 1 to 10 of 42

Thread: Location drop down by State and City

  1. #1
    Thread Starter
    Member damien's Avatar
    Join Date
    May 2009
    Location
    Melbourne, Australia
    Posts
    91
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Location drop down by State and City

    I'm trying to work out how I can use the location as a drop down for the area's my site deals with. I'll share what I have here so far, it works, just a few touches needed. It's not available in the dashboard edit so I've gotta work that out next.

    This is for version 2.9.1 of classipress. I'm not a code monkey either I'm just a curious person so I wont be very technical with this

    So it looks like this so far:








    So this is the code you could use to get such a menu happening.

    Open classipress/classifiedform/step1.php

    find:
    Code:
    		<label for="location"><?php _e('Location','cp'); ?> <span>*</span> <span style="display:none;"  class='ajax_errors' id='location_errors'></span></label>
    		<input type="text" id="location" class="adfields" name="location" size="50" maxlength="100" value="<?php echo $location; ?>" />
    replace it with:
    Code:
    <label for="location"><?php _e('Location','cp'); ?> <span>*</span> missing your location? suggest it! <span style="display:none;"  class='ajax_errors' id='location_errors'></span></label>
    <select name="country" onchange="htmlData('<? bloginfo('template_directory'); ?>/city.php', 'ch='+this.value)" />
    <option value="#">- Select Area -</option>
    <option value="Melbourne City">Melbourne City</option>
    <option value="Surrounding Areas">Surrounding Areas</option>
    <option value="Other Victoria">Other Victoria</option>
    </select>
    <div id="txtResult"> <select name="location"><option></option></select> </div>
    save it.

    Open a new txt file and call it city.php and fill it with these details:
    Code:
    <?php
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    
    // List of cities for melb city
    if ($_GET['ch'] == 'Melbourne City') {
       ?>
    <select name="location">
    <option value="Altona, victoria">Altona</option>
    <option value="Ascot Vale, victoria">Ascot Vale</option>
    <option value="Carlton, victoria">Carlton</option>
    <option value="Central Business District, Melbourne">Central Business District</option>
    <option value="Clifton Hills, victoria">Clifton Hills</option>
    <option value="Collingwood, victoria">Collingwood</option>
    <option value="Docklands, victoria">Docklands</option>
    <option value="East Melbourne, victoria">East Melbourne</option>
    <option value="Essendon, victoria">Essendon</option>
    <option value="Fitzroy, victoria">Fitzroy</option>
    <option value="Middle Park, victoria">Middle Park</option>
    <option value="North Carlton, victoria">North Carlton</option>
    <option value="North Fitzroy, victoria">North Fitzroy</option>
    <option value="North Melbourne, victoria">North Melbourne</option>
    <option value="North Melbourne, victoria">Parkville</option>
    <option value="Port Melbourne, victoria">Port Melbourne</option>
    <option value="Prahran, victoria">Prahran</option>
    <option value="Prahran, victoria">Richmond</option>
    <option value="South Melbourne, victoria">South Melbourne</option>
    <option value="South Yarra, victoria">South Yarra</option>
    <option value="Southbank, victoria">Southbank</option>
    <option value="St. Kilda, victoria">St. Kilda</option>
    <option value="St. Kilda Road, victoria">St. Kilda Road</option>
    <option value="St. Albans, victoria">St. Albans</option>
    <option value="Sunshine, victoria">Sunshine</option>
    <option value="Sydenham, victoria">Sydenham</option>
    <option value="West Melbourne, victoria">West Melbourne</option>
    <option value="Williamstown, victoria">Williamstown</option>
    </select>
    <?php
    }
    
    // List of cities for Surrounding Areas
    if ($_GET['ch'] == 'Surrounding Areas') {
       ?>
    <select name="location">
    <option value="Bacchus Marsh, victoria">Bacchus Marsh</option>
    <option value="Geelong, victoria">Geelong</option>
    <option value="Melton, victoria">Melton</option>
    <option value="Outer East, victoria, Australia">Outer East</option>
    <option value="Outer North, victoria, Australia">Outer North</option>
    <option value="Outer Northeast, victoria, Australia">Outer Northeast</option>
    <option value="Outer Southeast, victoria, Australia">Outer Southeast</option>
    <option value="Sunbury, victoria">Sunbury</option>
    </select>
    <?php
    }
    
    
    // List of cities for Other Victoria
    if ($_GET['ch'] == 'Other Victoria') {
       ?>
    <select name="location">
    <option value="Albury, victoria">Albury/Wodonga</option>
    <option value="Ballarat, victoria">Ballarat</option>
    <option value="Bendigo, victoria">Bendigo</option>
    <option value="Dandenong Ranges, victoria">Dandenong Ranges</option>
    <option value="Daylesford, victoria">Daylesford</option>
    <option value="Gippsland, victoria">Gippsland</option>
    <option value="Goldfields, victoria">Goldfields</option>
    <option value="Grampians, victoria">Grampians</option>
    <option value="Great Ocean Road, victoria">Great Ocean Road</option>
    <option value="Mildura, victoria">Mildura</option>
    <option value="Phillip Island, victoria">Phillip Island</option>
    <option value="Shepparton, victoria">Shepperton Area/The Murry</option>
    <option value="Swan Hill, victoria">Swan Hill</option>
    <option value="Warrnambool, victoria">Warrnambool</option>
    <option value="Yarra Valley, victoria">Yarra Valley</option>
    </select>
    <?php
    }
    ?>
    Save it and upload it to the classipress directory, that is the main folder with the changelog.txt and stuff,

    Now open a new txt file (list.js) and fill it with these details:
    Code:
    // select box
    function GetXmlHttpObject(handler)
    {
        var objXMLHttp=null
        if (window.XMLHttpRequest)
        {
            objXMLHttp=new XMLHttpRequest()
        }
        else if (window.ActiveXObject)
        {
            objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
        }
        return objXMLHttp
    }
     
    function stateChanged()
    {
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
        {
                document.getElementById("txtResult").innerHTML= xmlHttp.responseText;
        }
        else {
                //alert(xmlHttp.status);
        }
    }
     
    // Will populate data based on input
    function htmlData(url, qStr)
    {
        if (url.length==0)
        {
            document.getElementById("txtResult").innerHTML=""; 
            return;
        }
        xmlHttp=GetXmlHttpObject()
        if (xmlHttp==null)
        {
            alert ("Browser does not support HTTP Request");
            return;
        }
     
        url=url+"?"+qStr; 
        url=url+"&sid="+Math.random();
        xmlHttp.onreadystatechange=stateChanged;
        xmlHttp.open("GET",url,true) ;
        xmlHttp.send(null);
    }
    rename this txt file to list.js and upload it into the classipress/js folder.

    Now open classipress/header.php and add a link to the javascript file.
    Code:
    <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/list.js"></script>
    And now you have a half-decent working drop down menu that you need to go over and change the option values and names in the code. Now someone get it working in the dashboard

    - D.

  2. #2
    Veteran pointandstare's Avatar
    Join Date
    Apr 2009
    Location
    London, England
    Posts
    311
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Location drop down by State and City

    Good work.

    (My OCD tells me that you need to capitalise the V in Victoria )

  3. #3
    dubya's Avatar
    Join Date
    May 2009
    Location
    Canada
    Posts
    1,000
    Thanks
    115
    Thanked 107 Times in 93 Posts

    Re: Location drop down by State and City

    I'd be curious as to how this could be done in the new (old) submit form that will be in 2.92
    The search button. Your new best friend.
    - Dubya

  4. #4
    Thread Starter
    Member damien's Avatar
    Join Date
    May 2009
    Location
    Melbourne, Australia
    Posts
    91
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Location drop down by State and City

    Quote Originally Posted by dubya
    I'd be curious as to how this could be done in the new (old) submit form that will be in 2.93
    It shouldn't be too much different because it's just modified wordpress code for a drop down menu, the files and form will basically be/work the same.

  5. #5
    Thread Starter
    Member damien's Avatar
    Join Date
    May 2009
    Location
    Melbourne, Australia
    Posts
    91
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Location drop down by State and City

    I just modded the latest version 2.9.2 with that menu and it's all contained within post-form.php this time, instead of step1.php. Then you follow through with adding the city.php and .js file, & edit the header same as above.

  6. #6
    Veteran sonnycool's Avatar
    Join Date
    Mar 2009
    Location
    Malaysia
    Posts
    308
    Thanks
    32
    Thanked 2 Times in 2 Posts

    Re: Location drop down by State and City

    any lastest version ? cause 2.9.2 without step1

  7. #7
    Thread Starter
    Member damien's Avatar
    Join Date
    May 2009
    Location
    Melbourne, Australia
    Posts
    91
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Location drop down by State and City

    Quote Originally Posted by SonnyCooL
    any lastest version ? cause 2.9.2 without step1
    It's now post-form.php this time, instead of step1.php

    find @ about line 164

    Code:
    <label for="location"><?php _e('Location','cp'); ?> <span>*</span></label>
    				<input type="text" id="location" class="adfields" name="location" size="60" maxlength="100" value="<?php echo $_POST['location']; ?>" />
    replace with:

    Code:
    <label for="location"><?php _e('Location','cp'); ?> <span>*</span> missing your location? suggest it! <span style="display:none;"  class='ajax_errors' id='location_errors'></span></label>
    <select name="country" onchange="htmlData('<? bloginfo('template_directory'); ?>/city.php', 'ch='+this.value)" />
    <option value="#">- Select Area -</option>
    <option value="Melbourne City">Melbourne City</option>
    <option value="Surrounding Areas">Surrounding Areas</option>
    <option value="Other Victoria">Other Victoria</option>
    </select>
    <div id="txtResult"> <select name="location"><option></option></select> </div>
    and follow on from step two (city.php) above and change all the values I used to what you want.

  8. #8
    Rookie g-saint's Avatar
    Join Date
    Jun 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Location drop down by State and City

    If I do this with a custom field, not location, to be able to search it, do I need to set each value of each city in the city.php file to be <?php echo $_POST['city']; ?>

    Please help!

    Cheers...

  9. #9
    Thread Starter
    Member damien's Avatar
    Join Date
    May 2009
    Location
    Melbourne, Australia
    Posts
    91
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Location drop down by State and City

    Quote Originally Posted by g-saint
    If I do this with a custom field, not location, to be able to search it, do I need to set each value of each city in the city.php file to be <?php echo $_POST['city']; ?>

    Please help!

    Cheers...
    I've never used a custom field in wordpress yet so I'm clueless as to what needs to be done there... I'd hit http://wordpress.org/support/ and ask a guru there in the forums or search a bit.

  10. #10
    anunturitop_ro's Avatar
    Join Date
    May 2009
    Location
    Romania
    Posts
    69
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Location drop down by State and City

    Quote Originally Posted by Damien
    I'm trying to work out how I can use the location as a drop down for the area's my site deals with. I'll share what I have here so far, it works, just a few touches needed. It's not available in the dashboard edit so I've gotta work that out next.

    This is for version 2.9.1 of classipress. I'm not a code monkey either I'm just a curious person so I wont be very technical with this

    So it looks like this so far:








    So this is the code you could use to get such a menu happening.

    Open classipress/classifiedform/step1.php

    find:
    Code:
    		<label for="location"><?php _e('Location','cp'); ?> <span>*</span> <span style="display:none;"  class='ajax_errors' id='location_errors'></span></label>
    		<input type="text" id="location" class="adfields" name="location" size="50" maxlength="100" value="<?php echo $location; ?>" />
    replace it with:
    Code:
    <label for="location"><?php _e('Location','cp'); ?> <span>*</span> missing your location? suggest it! <span style="display:none;"  class='ajax_errors' id='location_errors'></span></label>
    <select name="country" onchange="htmlData('<? bloginfo('template_directory'); ?>/city.php', 'ch='+this.value)" />
    <option value="#">- Select Area -</option>
    <option value="Melbourne City">Melbourne City</option>
    <option value="Surrounding Areas">Surrounding Areas</option>
    <option value="Other Victoria">Other Victoria</option>
    </select>
    <div id="txtResult"> <select name="location"><option></option></select> </div>
    save it.

    Open a new txt file and call it city.php and fill it with these details:
    Code:
    <?php
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    
    // List of cities for melb city
    if ($_GET['ch'] == 'Melbourne City') {
       ?>
    <select name="location">
    <option value="Altona, victoria">Altona</option>
    <option value="Ascot Vale, victoria">Ascot Vale</option>
    <option value="Carlton, victoria">Carlton</option>
    <option value="Central Business District, Melbourne">Central Business District</option>
    <option value="Clifton Hills, victoria">Clifton Hills</option>
    <option value="Collingwood, victoria">Collingwood</option>
    <option value="Docklands, victoria">Docklands</option>
    <option value="East Melbourne, victoria">East Melbourne</option>
    <option value="Essendon, victoria">Essendon</option>
    <option value="Fitzroy, victoria">Fitzroy</option>
    <option value="Middle Park, victoria">Middle Park</option>
    <option value="North Carlton, victoria">North Carlton</option>
    <option value="North Fitzroy, victoria">North Fitzroy</option>
    <option value="North Melbourne, victoria">North Melbourne</option>
    <option value="North Melbourne, victoria">Parkville</option>
    <option value="Port Melbourne, victoria">Port Melbourne</option>
    <option value="Prahran, victoria">Prahran</option>
    <option value="Prahran, victoria">Richmond</option>
    <option value="South Melbourne, victoria">South Melbourne</option>
    <option value="South Yarra, victoria">South Yarra</option>
    <option value="Southbank, victoria">Southbank</option>
    <option value="St. Kilda, victoria">St. Kilda</option>
    <option value="St. Kilda Road, victoria">St. Kilda Road</option>
    <option value="St. Albans, victoria">St. Albans</option>
    <option value="Sunshine, victoria">Sunshine</option>
    <option value="Sydenham, victoria">Sydenham</option>
    <option value="West Melbourne, victoria">West Melbourne</option>
    <option value="Williamstown, victoria">Williamstown</option>
    </select>
    <?php
    }
    
    // List of cities for Surrounding Areas
    if ($_GET['ch'] == 'Surrounding Areas') {
       ?>
    <select name="location">
    <option value="Bacchus Marsh, victoria">Bacchus Marsh</option>
    <option value="Geelong, victoria">Geelong</option>
    <option value="Melton, victoria">Melton</option>
    <option value="Outer East, victoria, Australia">Outer East</option>
    <option value="Outer North, victoria, Australia">Outer North</option>
    <option value="Outer Northeast, victoria, Australia">Outer Northeast</option>
    <option value="Outer Southeast, victoria, Australia">Outer Southeast</option>
    <option value="Sunbury, victoria">Sunbury</option>
    </select>
    <?php
    }
    
    
    // List of cities for Other Victoria
    if ($_GET['ch'] == 'Other Victoria') {
       ?>
    <select name="location">
    <option value="Albury, victoria">Albury/Wodonga</option>
    <option value="Ballarat, victoria">Ballarat</option>
    <option value="Bendigo, victoria">Bendigo</option>
    <option value="Dandenong Ranges, victoria">Dandenong Ranges</option>
    <option value="Daylesford, victoria">Daylesford</option>
    <option value="Gippsland, victoria">Gippsland</option>
    <option value="Goldfields, victoria">Goldfields</option>
    <option value="Grampians, victoria">Grampians</option>
    <option value="Great Ocean Road, victoria">Great Ocean Road</option>
    <option value="Mildura, victoria">Mildura</option>
    <option value="Phillip Island, victoria">Phillip Island</option>
    <option value="Shepparton, victoria">Shepperton Area/The Murry</option>
    <option value="Swan Hill, victoria">Swan Hill</option>
    <option value="Warrnambool, victoria">Warrnambool</option>
    <option value="Yarra Valley, victoria">Yarra Valley</option>
    </select>
    <?php
    }
    ?>
    Save it and upload it to the classipress directory, that is the main folder with the changelog.txt and stuff,

    Now open a new txt file (list.js) and fill it with these details:
    Code:
    // select box
    function GetXmlHttpObject(handler)
    {
        var objXMLHttp=null
        if (window.XMLHttpRequest)
        {
            objXMLHttp=new XMLHttpRequest()
        }
        else if (window.ActiveXObject)
        {
            objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
        }
        return objXMLHttp
    }
     
    function stateChanged()
    {
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
        {
                document.getElementById("txtResult").innerHTML= xmlHttp.responseText;
        }
        else {
                //alert(xmlHttp.status);
        }
    }
     
    // Will populate data based on input
    function htmlData(url, qStr)
    {
        if (url.length==0)
        {
            document.getElementById("txtResult").innerHTML=""; 
            return;
        }
        xmlHttp=GetXmlHttpObject()
        if (xmlHttp==null)
        {
            alert ("Browser does not support HTTP Request");
            return;
        }
     
        url=url+"?"+qStr; 
        url=url+"&sid="+Math.random();
        xmlHttp.onreadystatechange=stateChanged;
        xmlHttp.open("GET",url,true) ;
        xmlHttp.send(null);
    }
    rename this txt file to list.js and upload it into the classipress/js folder.

    Now open classipress/header.php and add a link to the javascript file.
    Code:
    <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/list.js"></script>
    And now you have a half-decent working drop down menu that you need to go over and change the option values and names in the code. Now someone get it working in the dashboard

    - D.

    Thanks this is working for me ... But how can i make a drop down for price currently i want to have more than one curently and users to choise theyr price curently .. Do you understand what i want to say right ?? Sorry for my bad english

Page 1 of 5 123 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)