I am trying to verify a great contact form. When the user forgets the required input field, I fill the empty variable with the default text.
My current solution uses nine if . Is there a better way to do this with less code ?
html: <xehases class="" id="xehases"></xehases>
var onoma = $("#fname").val(); var eponimo = $("#lname").val(); var email = $("#email").val(); var diefthinsi = $("#address").val(); var poli = $("#city").val(); var xora = $("#country").val(); var katigoriaDiafimisis = $("#AdCategory").val(); var plano = $("#plan").val(); var istoselida = $("#website").val(); var epixirisi = $("#company").val(); var minima = $("#message").val(); var missing = ' '; if (onoma === "") { missing += 'Όνομα '; $("xehases#xehases").html(missing); } else { $("xehases#xehases").html(missing); } if (eponimo === "") { missing += 'Επώνυμο '; $("xehases#xehases").html(missing); } else { $("xehases#xehases").html(missing); } if (email === "") { missing += 'email '; $("xehases#xehases").html(missing); } else { $("xehases#xehases").html(missing); } if (poli === "") { missing += 'Πόλη '; $("xehases#xehases").html(missing); } else { $("xehases#xehases").html(missing); } if (xora === "please choose a category") { missing += 'Χώρα '; $("xehases#xehases").html(missing); } else { $("xehases#xehases").html(missing); } if (plano === "") { missing += 'Πλάνο '; $("xehases#xehases").html(missing); } else { $("xehases#xehases").html(missing); } if (katigoriaDiafimisis === "") { missing += 'Κατηγορία Διαφήμισης '; $("xehases#xehases").html(missing); } else { $("xehases#xehases").html(missing); } if (epixirisi === "") { missing += 'Επιχείρηση '; $("xehases#xehases").html(missing); } else { $("xehases#xehases").html(missing); } if (minima === "") { missing += 'Μήνυμα '; $("xehases#xehases").html(missing); } else { $("xehases#xehases").html(missing); }
user7038047
source share