retain show/hide states upon form validation
In my form I show/hide certain divs based on the radio button s开发者_StackOverflowelection by the user. For example:
$('input[name=\'pick_up_point\']').change(function() {
if($($(this)).val() == 'pick_up_airport')
{
$('#pick_up_airport_div').slideDown();
$('#start_point_div').hide();
}
});
Now when the form is submitted, and if there is an error the form is redisplayed. The validation is working fine, except of course the divs are back in their original states. How can I retain the show/hide states?
Onload of the page you could fire the change event for all radio buttons:
$('input[name=\'pick_up_point\']').trigger('change');
This would need to be called after you've defined the change handler.
精彩评论