Hi there,

I'm sorry this is a pretty newbie question....


I am using JQuery with an xml file and autocomplete. What I am trying
to achieve is to use an xml file as my data source to autocomplete
cities in a form once a user selects their province. When a user
selects a particular province then only the cities in that province
will be listed by the autocomplete script as the user starts to type
in the 'city' form field.

My problem here is that I am trying to use the array 'towncity' as my
data source for autocomplete and change the contents of the array when
the province select box #province is changed. However, I can not get
my $('#province').change(function().... to affect the array 'towncity'
that I have declared outside of the function....

        <script type="text/javascript">
        $(document).ready(function() {
                var towncity = window.towncity = new Array();
                $("#city").autocomplete(towncity);
                $.preloadCssImages();
                $('div.jshide').show();
                $("#tenantForm").validate({
                  rules: {
                        name: {
                          required: true,
                          minlength: 2
                        },
                        province:"required",
                        ccom:"required",
                        occupied: "required",
                        rented:"required",
                        condo:"required",
                        payment:"required"

                  }
                });


                $("#renewdate").datepicker({
                        dateFormat: "d M, yy",
                        showOn: "both",
                        buttonImage: "images/calendar.gif",
                        buttonImageOnly: true
                });

                $('#province').change(function() {
                        var currprov = $('option:selected', this).text();

                        $(function() {
                                $.ajax({
                                        type: "GET",
                                        url: "xml/location.xml",
                                        dataType: "xml",
                                        success: function(xml) {

                                                $(xml).find("[EMAIL 
PROTECTED]'"+ currprov +"'] >
TOWN_CITY_NAME").each(function(){
                                                        towncity = 
$(this).text();
                                                });
                                }
                                });
                        });
                });
        });
    </script>


Anyone have any ideas?

Thanks,
Mat

Reply via email to