views:

436

answers:

1

I'm styling a form with Jqtransform script. The form includes a selector which enlist some cities, when i click a one, it should update the selector below it with some locations within that city.

here is the code of the selector

<select name="city" id="city" class="wide" onchange="populateDestrict(this)"> 

It was working fine with default style , but after applying JQ, it lost it's functionality

I asked a question before here LINK

and i did as Dormilich did by writing:

     $(function() { 
$("form.jqtransform").jqTransform();
$("#city").change(populateDestrict(this)); 
}); 

But it didn't work !

here is also the code of the function if it helps

<script language="javascript">
    function populateDestrict(obj){
        var city=obj.value;
            if(city!=""){
                $.post('city_state.php',{ city: city},function(xml){ 
                    $("#state").removeOption(/./);
                    $("district",xml).each(function() {
                    $("#state").addOption($("key",this).text(), $("value",this).text());
                });
            });
            }
    }
</script>

Any help people ???????? Thanks

A: 
$("#city").change(populateDestrict);

In JavaScript (unlike to the HTML event attributes) you have to assign a function reference. using parentheses with that will cause the function’s return value to be assigned instead of the function (IE does its own thing of course).

you also have to edit your function accordingly—simply use this instead of obj. as the first and only parameter the event object will be passed (not in IE, though, but jQuery takes care of that)

Dormilich
thanks a lot for you effort. really appreciated.I did as you said : putting that code - nothing changedalso changing obj with this in the function code itself- also nothing changes !I wanted also to say that when i select the city, the search shows results for that city, but the selector below doesn't update according to it !It just remains including locations for the first one (not the selected city)also the form is functioning normally without jqtransform,so I don't think the main function code is wrong.thanks a lot , and waiting for your reply
Newbie
does your function start like this? function populateDestrict(){ var city=this.value;
Dormilich