Comme une réponse alternative démontre un peu plus de concepts avancés jQuery pour vous, considérez le javascript suivant:
$(document).ready(function() {
// cache anything reused in variables
var $zonaenvio = $("#zonaenvio");
var $gelypilas = $('#gelypilas');
var $totalprecio = $('#totalprecio');
var $totalSpan = $('#preciototal');
// declare a function that does everything
var updatePrice = function() {
// get the value of the selected product, or 0 if nothing selected
var productAmount = parseInt($zonaenvio.val() || '0');
if (productAmount > 0) {
// if something selected, calculate correct total and show it
var correctTotal = productAmount + ($gelypilas.is(':checked') ? 25 : 0);
$totalSpan.text(correctTotal);
$totalprecio.show('slow');
} else {
// otherwise, if nothing selected, hide the total information
$totalprecio.hide();
}
};
// bind the function to the input events
$zonaenvio.change(updatePrice).change(); // trigger once if needed
$gelypilas.change(updatePrice);
});
Est-ce que cela a du sens? Voir here pour un exemple de travail jsFiddle.
J'ai beaucoup aimé ... beaucoup – sebas