|
| 1 | +function formValidation() { |
| 2 | + var uname = document.registration.username; |
| 3 | + var uadd = document.registration.address; |
| 4 | + var ucountry = document.registration.country; |
| 5 | + var uzip = document.registration.zip; |
| 6 | + var uemail = document.registration.email; |
| 7 | + var usex = document.registration.sex; |
| 8 | + var uabout = document.registration.desc; |
| 9 | + var ulang = document.registration.language; |
| 10 | + var uyear = document.registration.year; |
| 11 | + var udegree = document.registration.degree; |
| 12 | + var uinsti = document.registration.insti; |
| 13 | + var ures = document.registration.result; |
| 14 | + var upname = document.registration.pname; |
| 15 | + var upabout = document.registration.pabout; |
| 16 | + var upos = document.registration.position; |
| 17 | + var udur = document.registration.duration; |
| 18 | + var ucomp = document.registration.company; |
| 19 | + |
| 20 | + if (allLetter(uname)) { |
| 21 | + if (alphanumeric(uadd)) { |
| 22 | + if (countryselect(ucountry)) { |
| 23 | + if (allnumeric(uzip)) { |
| 24 | + if (ValidateEmail(uemail, mail)) { |
| 25 | + if (validsex(usex)) { |
| 26 | + if (allnumeric(uyear)) { |
| 27 | + checkAbout(uabout), |
| 28 | + lang(ulang), |
| 29 | + education(uyear, udegree, uinsti, ures), |
| 30 | + address(uadd, ucountry, uzip), |
| 31 | + project(upname, upabout), |
| 32 | + experience(ucomp, udur, upos); |
| 33 | + alert('Form Successfully Submitted'); |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | + return false; |
| 42 | +} |
| 43 | + |
| 44 | +function experience(ucomp, udur, upos) { |
| 45 | + |
| 46 | + if (ucomp.value == "" || udur.value == "" || upos.value == "") { |
| 47 | + document.getElementById("expinfo").remove() |
| 48 | + } |
| 49 | + else { |
| 50 | + document.getElementsByClassName("position")[0].innerHTML = upos.value |
| 51 | + document.getElementsByClassName("company")[0].innerHTML = ucomp.value |
| 52 | + document.getElementsByClassName("duration")[0].innerHTML = udur.value |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +function education(uyear, udegree, uinsti, ures) { |
| 57 | + |
| 58 | + document.getElementsByClassName("yr")[0].innerHTML = uyear.value |
| 59 | + document.getElementsByClassName("deg")[0].innerHTML = udegree.value |
| 60 | + document.getElementsByClassName("insti")[0].innerHTML = uinsti.value |
| 61 | + document.getElementsByClassName("res")[0].innerHTML = ures.value |
| 62 | + |
| 63 | +} |
| 64 | + |
| 65 | +function project(upname, upabout) { |
| 66 | + if (upname.value !== "" || upabout.value !== "") { |
| 67 | + document.getElementsByClassName("pname")[0].innerHTML = upname.value |
| 68 | + document.getElementsByClassName("pabout")[0].innerHTML = upabout.value |
| 69 | + } |
| 70 | + else { |
| 71 | + document.getElementById("pinfo").remove() |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +function checkAbout(uabout) { |
| 76 | + if (uabout.value.trim() !== "") |
| 77 | + document.getElementById("about").innerHTML = uabout.value.trim() |
| 78 | + else |
| 79 | + document.getElementById("about").parentElement.remove() |
| 80 | +} |
| 81 | + |
| 82 | +function address(uadd, ucountry, uzip) { |
| 83 | + var address = "" |
| 84 | + if (uadd.value.trim() !== "") |
| 85 | + address += uadd.value.trim() + "<br>" |
| 86 | + address += ucountry.value + "<br>" |
| 87 | + if (uzip.value) |
| 88 | + address += uzip.value |
| 89 | + document.getElementById("address").innerHTML = address |
| 90 | +} |
| 91 | + |
| 92 | +function lang(ulang) { |
| 93 | + var lang = "" |
| 94 | + |
| 95 | + for (var i of ulang) { |
| 96 | + if (i.checked) |
| 97 | + lang += i.value + "<br>" |
| 98 | + } |
| 99 | + document.getElementById("lang").innerHTML = lang |
| 100 | +} |
| 101 | + |
| 102 | +function allLetter(uname) { |
| 103 | + var letters = /^[A-Za-z ]+$/; //Regex |
| 104 | + if (uname.value.trim().match(letters)) { |
| 105 | + document.getElementById("name").innerHTML = uname.value.toUpperCase() |
| 106 | + return true; |
| 107 | + } |
| 108 | + else { |
| 109 | + alert('Username must have alphabet characters only'); |
| 110 | + uname.focus(); |
| 111 | + return false; |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +function alphanumeric(uadd) { |
| 116 | + var letters = /^[0-9a-zA-Z/ ]+$/; |
| 117 | + if (uadd.value.trim().match(letters) || uadd.value.trim() === "") { |
| 118 | + return true; |
| 119 | + } |
| 120 | + else { |
| 121 | + alert('User address must have alphanumeric characters only'); |
| 122 | + uadd.focus(); |
| 123 | + return false; |
| 124 | + } |
| 125 | +} |
| 126 | + |
| 127 | +function countryselect(ucountry) { |
| 128 | + if (ucountry.value == "Default") { |
| 129 | + alert('Select your country from the list'); |
| 130 | + ucountry.focus(); |
| 131 | + return false; |
| 132 | + } |
| 133 | + else { |
| 134 | + return true; |
| 135 | + } |
| 136 | +} |
| 137 | + |
| 138 | +function allnumeric(uzip) { |
| 139 | + var numbers = /^[0-9]+$/; |
| 140 | + if (uzip.value.trim().match(numbers) || uzip.value.trim() === "") { |
| 141 | + return true; |
| 142 | + } |
| 143 | + else { |
| 144 | + alert('ZIP code must have numeric characters only'); |
| 145 | + uzip.focus(); |
| 146 | + return false; |
| 147 | + } |
| 148 | +} |
| 149 | + |
| 150 | +function ValidateEmail(uemail) { |
| 151 | + var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; |
| 152 | + if (uemail.value.match(mailformat)) { |
| 153 | + document.getElementById("mail").href = "mailto:" + uemail.value |
| 154 | + document.getElementById("mail").innerHTML = uemail.value |
| 155 | + return true; |
| 156 | + } |
| 157 | + else { |
| 158 | + alert("You have entered an invalid email address!"); |
| 159 | + uemail.focus(); |
| 160 | + return false; |
| 161 | + } |
| 162 | +} |
| 163 | + |
| 164 | +function validsex(usex) { |
| 165 | + if (usex[0].checked || usex[1].checked) { |
| 166 | + console.log("assets/" + (usex[0].checked ? "male.png" : "female.png")) |
| 167 | + document.getElementsByTagName("img")[0].src = "./assets/" + (usex[0].checked ? "male.png" : "female.png") |
| 168 | + console.log(document.getElementsByTagName("img")[0].src) |
| 169 | + document.getElementsByTagName("h4")[0].innerHTML = usex[0].checked ? "MALE" : "FEMALE" |
| 170 | + return true; |
| 171 | + } |
| 172 | + else { |
| 173 | + alert('Select Male/Female'); |
| 174 | + usex[0].focus(); |
| 175 | + return false; |
| 176 | + } |
| 177 | +} |
| 178 | +document.getElementById("blue").addEventListener("click", blue) |
| 179 | +function blue() { |
| 180 | + document.getElementById("theme").setAttribute("href", "./themes/blue.css") |
| 181 | +} |
| 182 | + |
| 183 | +document.getElementById("default").addEventListener("click", lavender) |
| 184 | +function lavender() { |
| 185 | + document.getElementById("theme").setAttribute("href", "./themes/resume.css") |
| 186 | +} |
| 187 | + |
| 188 | +document.getElementById("grey").addEventListener("click",grey ) |
| 189 | +function grey() { |
| 190 | + document.getElementById("theme").setAttribute("href", "./themes/grey.css") |
| 191 | +} |
0 commit comments