napisałem taki kod:
Kod
<script>
$("#btnSubmit").click(function() {
var fields = false;
var name = $('#contact_form_name').val(); // input type=text
var email = $('#contact_form_email').val(); // input type=email
var theme = $('#contact_form_theme').val(); // input type=text
var message = $('#contact_form_message').val(); // type textarea
var policy = $('#contact_form_policy').is(':checked'); // input type=checkbox
// INFO: Dla formularza id="formContact" wspolny dla wszystkich pol jes atrybut required="required".
if (!name || !email || !theme || !message || !policy) { fields = true; }
if ((!fields) && ($('#fieldProgress').val() != '')) {
setTimeout(function () {
var newprogress = 100;
$('#progressBox').removeClass('hidden');
$('#progressBar').width(newprogress + "%").attr('aria-valuenow', newprogress);
}, 1000);
}
});
</script>
$("#btnSubmit").click(function() {
var fields = false;
var name = $('#contact_form_name').val(); // input type=text
var email = $('#contact_form_email').val(); // input type=email
var theme = $('#contact_form_theme').val(); // input type=text
var message = $('#contact_form_message').val(); // type textarea
var policy = $('#contact_form_policy').is(':checked'); // input type=checkbox
// INFO: Dla formularza id="formContact" wspolny dla wszystkich pol jes atrybut required="required".
if (!name || !email || !theme || !message || !policy) { fields = true; }
if ((!fields) && ($('#fieldProgress').val() != '')) {
setTimeout(function () {
var newprogress = 100;
$('#progressBox').removeClass('hidden');
$('#progressBar').width(newprogress + "%").attr('aria-valuenow', newprogress);
}, 1000);
}
});
</script>
Przed wykonaniem if ((!fields) && ($('#fieldProgress').val() != '')) należy sprawdzić,
czy wszystkie powyższe o różnych typach pola z tylko jednym wspólnym atrybutem dla wszystkich required="required" zostały wypełnione.
Jak uprościć kod, pozbyć się tylu var'ów?
Tak, aby było super PRO, bo obecnie po prostu działa, a chciałbym lepiej.