// user fill all fields as it should, so form can be submitted
conForm.submit(function(e){
var isValidForm = true;
// prevent user from hitting submit button with empty form.
var tempval = document.getElementById('fullname').value;
if(tempval.length ==0){
//jQuery('#p_username').focus();
jQuery('#fullname').addClass('bordered2');
jQuery('#fullname').removeClass('good_input');
jQuery("#fullname").attr("placeholder", "Εισάγετε το όνομα σας").placeholder();
isValidForm = false;
}
var sEmail = jQuery('#customeremail').val();
if (jQuery.trim(sEmail).length == 0) {
// if user leave the field empty
jQuery('#customeremail').removeClass('good_input');
jQuery('#customeremail').addClass('bordered2');
jQuery("#customeremail").attr("placeholder", "Εισάγετε το email σας").placeholder();
isValidForm = false;
}
if (validateEmail(sEmail)) {
// if the e-mail is valid
jQuery('#customeremail').removeClass('bordered2');
jQuery('#customeremail').addClass('good_input');
} else {
// if the e-mail is NOT valid
jQuery('#customeremail').removeClass('good_input');
jQuery('#customeremail').addClass('bordered2');
sEmail = "";
jQuery("#customeremail").val(sEmail);
jQuery("#customeremail").attr("placeholder", "Εισάγετε υπαρκτό email").placeholder();
isValidForm = false;
}
var tempval = document.getElementById('phone').value;
if(tempval.length ==0){
//jQuery('#p_username').focus();
jQuery('#phone').addClass('bordered2');
jQuery('#phone').removeClass('good_input');
jQuery("#phone").attr("placeholder", "Εισάγετε το τηλέφωνο σας").placeholder();
isValidForm = false;
}
return isValidForm;
})
UPDATE: Removed the .placeholder() code that was breaking the logic.
// user fill all fields as it should, so form can be submitted
conForm.submit(function(e){
var isValidForm = true;
// prevent user from hitting submit button with empty form.
var tempval = document.getElementById('fullname').value;
if(tempval.length ==0){
//jQuery('#p_username').focus();
jQuery('#fullname').addClass('bordered2');
jQuery('#fullname').removeClass('good_input');
jQuery("#fullname").attr("placeholder", "Εισάγετε το όνομα σας").placeholder();
isValidForm = false;
}
var sEmail = jQuery('#customeremail').val();
if (jQuery.trim(sEmail).length == 0) {
// if user leave the field empty
jQuery('#customeremail').removeClass('good_input');
jQuery('#customeremail').addClass('bordered2');
jQuery("#customeremail").attr("placeholder", "Εισάγετε το email σας").placeholder();
isValidForm = false;
}
if (validateEmail(sEmail)) {
// if the e-mail is valid
jQuery('#customeremail').removeClass('bordered2');
jQuery('#customeremail').addClass('good_input');
} else {
// if the e-mail is NOT valid
jQuery('#customeremail').removeClass('good_input');
jQuery('#customeremail').addClass('bordered2');
sEmail = "";
jQuery("#customeremail").val(sEmail);
jQuery("#customeremail").attr("placeholder", "Εισάγετε υπαρκτό email").placeholder();
isValidForm = false;
}
var tempval = document.getElementById('phone').value;
if(tempval.length ==0){
//jQuery('#p_username').focus();
jQuery('#phone').addClass('bordered2');
jQuery('#phone').removeClass('good_input');
jQuery("#phone").attr("placeholder", "Εισάγετε το τηλέφωνο σας").placeholder();
isValidForm = false;
}
return isValidForm;
})
// user fill all fields as it should, so form can be submitted
conForm.submit(function(e){
var isValidForm = true;
// prevent user from hitting submit button with empty form.
var tempval = document.getElementById('fullname').value;
if(tempval.length ==0){
//jQuery('#p_username').focus();
jQuery('#fullname').addClass('bordered2');
jQuery('#fullname').removeClass('good_input');
jQuery("#fullname").attr("placeholder", "Εισάγετε το όνομα σας");
isValidForm = false;
}
var sEmail = jQuery('#customeremail').val();
if (jQuery.trim(sEmail).length == 0) {
// if user leave the field empty
jQuery('#customeremail').removeClass('good_input');
jQuery('#customeremail').addClass('bordered2');
jQuery("#customeremail").attr("placeholder", "Εισάγετε το email σας");
isValidForm = false;
}
if (validateEmail(sEmail)) {
// if the e-mail is valid
jQuery('#customeremail').removeClass('bordered2');
jQuery('#customeremail').addClass('good_input');
} else {
// if the e-mail is NOT valid
jQuery('#customeremail').removeClass('good_input');
jQuery('#customeremail').addClass('bordered2');
sEmail = "";
jQuery("#customeremail").val(sEmail);
jQuery("#customeremail").attr("placeholder", "Εισάγετε υπαρκτό email");
isValidForm = false;
}
var tempval = document.getElementById('phone').value;
if(tempval.length ==0){
//jQuery('#p_username').focus();
jQuery('#phone').addClass('bordered2');
jQuery('#phone').removeClass('good_input');
jQuery("#phone").attr("placeholder", "Εισάγετε το τηλέφωνο σας");
isValidForm = false;
}
return isValidForm;
})
UPDATE: Removed the .placeholder() code that was breaking the logic.
// user fill all fields as it should, so form can be submitted conForm.submit(function(e){
// user fill all fields as it should, so form can be submitted
conForm.submit(function(e){ var isValidForm = true;
// prevent user from hitting submit button with empty form.
var tempval = document.getElementById('fullname').value;
if(tempval.length ==0){
//jQuery('#p_username').focus();
jQuery('#fullname').addClass('bordered2');
jQuery('#fullname').removeClass('good_input');
jQuery("#fullname").attr("placeholder", "Εισάγετε το όνομα σας").placeholder();
isValidForm = false;
}
var sEmail = jQuery('#customeremail').val();
if (jQuery.trim(sEmail).length == 0) {
// if user leave the field empty
jQuery('#customeremail').removeClass('good_input');
jQuery('#customeremail').addClass('bordered2');
jQuery("#customeremail").attr("placeholder", "Εισάγετε το email σας").placeholder();
isValidForm = false;
}
if (validateEmail(sEmail)) {
// if the e-mail is valid
jQuery('#customeremail').removeClass('bordered2');
jQuery('#customeremail').addClass('good_input');
} else {
// if the e-mail is NOT valid
jQuery('#customeremail').removeClass('good_input');
jQuery('#customeremail').addClass('bordered2');
sEmail = "";
jQuery("#customeremail").val(sEmail);
jQuery("#customeremail").attr("placeholder", "Εισάγετε υπαρκτό email").placeholder();
isValidForm = false;
}
var tempval = document.getElementById('phone').value;
if(tempval.length ==0){
//jQuery('#p_username').focus();
jQuery('#phone').addClass('bordered2');
jQuery('#phone').removeClass('good_input');
jQuery("#phone").attr("placeholder", "Εισάγετε το τηλέφωνο σας").placeholder();
isValidForm = false;
}
return isValidForm;
})
// user fill all fields as it should, so form can be submitted conForm.submit(function(e){
var isValidForm = true;
// prevent user from hitting submit button with empty form.
var tempval = document.getElementById('fullname').value;
if(tempval.length ==0){
//jQuery('#p_username').focus();
jQuery('#fullname').addClass('bordered2');
jQuery('#fullname').removeClass('good_input');
jQuery("#fullname").attr("placeholder", "Εισάγετε το όνομα σας").placeholder();
isValidForm = false;
}
var sEmail = jQuery('#customeremail').val();
if (jQuery.trim(sEmail).length == 0) {
// if user leave the field empty
jQuery('#customeremail').removeClass('good_input');
jQuery('#customeremail').addClass('bordered2');
jQuery("#customeremail").attr("placeholder", "Εισάγετε το email σας").placeholder();
isValidForm = false;
}
if (validateEmail(sEmail)) {
// if the e-mail is valid
jQuery('#customeremail').removeClass('bordered2');
jQuery('#customeremail').addClass('good_input');
} else {
// if the e-mail is NOT valid
jQuery('#customeremail').removeClass('good_input');
jQuery('#customeremail').addClass('bordered2');
sEmail = "";
jQuery("#customeremail").val(sEmail);
jQuery("#customeremail").attr("placeholder", "Εισάγετε υπαρκτό email").placeholder();
isValidForm = false;
}
var tempval = document.getElementById('phone').value;
if(tempval.length ==0){
//jQuery('#p_username').focus();
jQuery('#phone').addClass('bordered2');
jQuery('#phone').removeClass('good_input');
jQuery("#phone").attr("placeholder", "Εισάγετε το τηλέφωνο σας").placeholder();
isValidForm = false;
}
return isValidForm;
})
// user fill all fields as it should, so form can be submitted
conForm.submit(function(e){ var isValidForm = true;
// prevent user from hitting submit button with empty form.
var tempval = document.getElementById('fullname').value;
if(tempval.length ==0){
//jQuery('#p_username').focus();
jQuery('#fullname').addClass('bordered2');
jQuery('#fullname').removeClass('good_input');
jQuery("#fullname").attr("placeholder", "Εισάγετε το όνομα σας").placeholder();
isValidForm = false;
}
var sEmail = jQuery('#customeremail').val();
if (jQuery.trim(sEmail).length == 0) {
// if user leave the field empty
jQuery('#customeremail').removeClass('good_input');
jQuery('#customeremail').addClass('bordered2');
jQuery("#customeremail").attr("placeholder", "Εισάγετε το email σας").placeholder();
isValidForm = false;
}
if (validateEmail(sEmail)) {
// if the e-mail is valid
jQuery('#customeremail').removeClass('bordered2');
jQuery('#customeremail').addClass('good_input');
} else {
// if the e-mail is NOT valid
jQuery('#customeremail').removeClass('good_input');
jQuery('#customeremail').addClass('bordered2');
sEmail = "";
jQuery("#customeremail").val(sEmail);
jQuery("#customeremail").attr("placeholder", "Εισάγετε υπαρκτό email").placeholder();
isValidForm = false;
}
var tempval = document.getElementById('phone').value;
if(tempval.length ==0){
//jQuery('#p_username').focus();
jQuery('#phone').addClass('bordered2');
jQuery('#phone').removeClass('good_input');
jQuery("#phone").attr("placeholder", "Εισάγετε το τηλέφωνο σας").placeholder();
isValidForm = false;
}
return isValidForm;
})
I'd remove the first instance of e.preventDefault(); and introduce a validation flag that defaults to true. Replace all of the other instances of e.preventDefault(); with a line that sets the flag to false and then return the flag at the end of the code.
Like this:
// user fill all fields as it should, so form can be submitted conForm.submit(function(e){
var isValidForm = true;
// prevent user from hitting submit button with empty form.
var tempval = document.getElementById('fullname').value;
if(tempval.length ==0){
//jQuery('#p_username').focus();
jQuery('#fullname').addClass('bordered2');
jQuery('#fullname').removeClass('good_input');
jQuery("#fullname").attr("placeholder", "Εισάγετε το όνομα σας").placeholder();
isValidForm = false;
}
var sEmail = jQuery('#customeremail').val();
if (jQuery.trim(sEmail).length == 0) {
// if user leave the field empty
jQuery('#customeremail').removeClass('good_input');
jQuery('#customeremail').addClass('bordered2');
jQuery("#customeremail").attr("placeholder", "Εισάγετε το email σας").placeholder();
isValidForm = false;
}
if (validateEmail(sEmail)) {
// if the e-mail is valid
jQuery('#customeremail').removeClass('bordered2');
jQuery('#customeremail').addClass('good_input');
} else {
// if the e-mail is NOT valid
jQuery('#customeremail').removeClass('good_input');
jQuery('#customeremail').addClass('bordered2');
sEmail = "";
jQuery("#customeremail").val(sEmail);
jQuery("#customeremail").attr("placeholder", "Εισάγετε υπαρκτό email").placeholder();
isValidForm = false;
}
var tempval = document.getElementById('phone').value;
if(tempval.length ==0){
//jQuery('#p_username').focus();
jQuery('#phone').addClass('bordered2');
jQuery('#phone').removeClass('good_input');
jQuery("#phone").attr("placeholder", "Εισάγετε το τηλέφωνο σας").placeholder();
isValidForm = false;
}
return isValidForm;
})
I'd remove the first instance of e.preventDefault(); and introduce a validation flag that defaults to true. Replace all of the other instances of e.preventDefault(); with a line that sets the flag to false and then return the flag at the end of the code.
Like this:
// user fill all fields as it should, so form can be submitted conForm.submit(function(e){
var isValidForm = true;
// prevent user from hitting submit button with empty form.
var tempval = document.getElementById('fullname').value;
if(tempval.length ==0){
//jQuery('#p_username').focus();
jQuery('#fullname').addClass('bordered2');
jQuery('#fullname').removeClass('good_input');
jQuery("#fullname").attr("placeholder", "Εισάγετε το όνομα σας").placeholder();
isValidForm = false;
}
var sEmail = jQuery('#customeremail').val();
if (jQuery.trim(sEmail).length == 0) {
// if user leave the field empty
jQuery('#customeremail').removeClass('good_input');
jQuery('#customeremail').addClass('bordered2');
jQuery("#customeremail").attr("placeholder", "Εισάγετε το email σας").placeholder();
isValidForm = false;
}
if (validateEmail(sEmail)) {
// if the e-mail is valid
jQuery('#customeremail').removeClass('bordered2');
jQuery('#customeremail').addClass('good_input');
} else {
// if the e-mail is NOT valid
jQuery('#customeremail').removeClass('good_input');
jQuery('#customeremail').addClass('bordered2');
sEmail = "";
jQuery("#customeremail").val(sEmail);
jQuery("#customeremail").attr("placeholder", "Εισάγετε υπαρκτό email").placeholder();
isValidForm = false;
}
var tempval = document.getElementById('phone').value;
if(tempval.length ==0){
//jQuery('#p_username').focus();
jQuery('#phone').addClass('bordered2');
jQuery('#phone').removeClass('good_input');
jQuery("#phone").attr("placeholder", "Εισάγετε το τηλέφωνο σας").placeholder();
isValidForm = false;
}
return isValidForm;
})