Just put it in a function, then call it on document ready too, like so:
$(function () {
yourFunction(); //this calls it on load
$("select#marca").change(yourFunction);
});
function yourFunction() {
var marca = $("select#marca option:selected").attr('value');
$("select#modello").html(attendere);
$.post("select.php", {id_marca:marca}, function(data){
$("select#modello").html(data);
});
}
Not entirely sure if this is what you're looking for, but if you were hoping to run the
safe()
code when the page loads, try this.
Example: http://jsfiddle.net/ewNEc/
$(function() {
function safe(){
if( this.checked ){
$("select[name='sort']").attr("disabled", "disabled");
$("input[name='group']").attr("disabled", "disabled")
} else {
$("select[name='sort']").attr("disabled", false);
$("input[name='group']").attr("disabled", false)
}
}
$('input#safe').change(safe).triggerHandler("change");
});
Uses
.triggerHandler()
to fire the handler without changing the state.
0 Comments