开发者

Lost OnChange after form Validation

I'm using codeigniter and when selecting a dropdown form onchange works and i get my second field ok(Country->City). When i submit the form with errors, the page reloads with the errors displayed but my onchange stops working. Any ideas for what's going on? Hmm, here's what i'm doing. User get's to homepage and fills the form, the onchange is working. User then submits the form with an error and i check the validation and load a new page(register) with the same onchange function. I tried to change the function name (getLocal) to another name but the result is the same. Tried to use live.("change", getLocal) and th开发者_运维百科e result is the same, no firing on the register page...

 
function getLocal(){
    $("#city").load("home/ajaxlocal", {country: $(this).val()} );
   //alert($(this).val());

    return false;
}

..............

$js = 'id="country"';
    
    $(document).ready(function() {
    $("#country select").bind("change", getLocal);
        });
    
td echo form_label('Country :', $country); 
td id="country">echo form_dropdown('country', $country,$ct,$js);


IF yo arent reloading the page, but reloading elements with AJAX, the jquery will not bind to those new elements if you specify them in the ready() function.

$(document).ready(function() {
    $("#country select").bind("change", getLocal);
});

This is loading this onload - try using .live()

http://api.jquery.com/live/

This method is a variation on the basic .bind() method for attaching event handlers to elements. When .bind() is called, the elements that the jQuery object refers to get the handler attached; elements that get introduced later do not, so they would require another .bind() call.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜