Skip to content
Snippets Groups Projects
Commit 97fc6636 authored by Oliver Green's avatar Oliver Green
Browse files

starting inputvalidation of form

parent 903e59f6
No related branches found
No related tags found
No related merge requests found
File moved
......@@ -3,7 +3,72 @@
<link href="client.css" type="text/css" rel="stylesheet">
<script src="client.js" type="text/javascript"></script>
<script src="serverstub.js" type="text/javascript"></script>
<script type="text/view" id="welcomeview">
<div class="welcome">
<img src="wimage.png" alt="logo and slogan">
<div class="form-elements" id="login">
<form id="loginform" onsubmit="return inputValidation()">
<div class="form-input">
<label for="email">Email</label>
<input type="text" id="email" name="email" size="18">
</div>
<div class="form-input">
<label for="password">Password</label>
<input type="text" id="password" name="password" size="18">
</div>
<input type="submit" value="Login">
</form>
<form id="signupform" onsubmit="return inputValidation()">
<h2>Sign up here</h2>
<div class="form-input">
<label for="fname">First name</label>
<input type="text" id="fname" name="fname" size="18">
</div>
<div class="form-input">
<label for="lname">Family name</label>
<input type="text" id="lname" name="lname" size="18">
</div>
<div class="form-input">
<label for="gender">Gender</label>
<select id="gender" name="gender" style="width:169;">
<option value="male">Male</option>
<option value="female">Female</option>
<option value="other">Other</option>
</select>
</div>
<div class="form-input">
<label for="city">City</label>
<input type="text" id="city" name="city" size="18">
</div>
<div class="form-input">
<label for="country">Country</label>
<input type="text" id="country" name="country" size="18">
</div>
<div class="form-input">
<label for="email">Email</label>
<input type="text" id="email" name="email" size="18">
</div>
<div class="form-input">
<label for="password">Password</label>
<input type="text" id="password" name="password" size="18">
</div>
<div class="form-input">
<label for="password2">Repeat PSW</label>
<input type="text" id="password2" name="password2" size="18">
</div>
<div class="form-input">
<input type="submit" value="Sign Up">
</div>
</form>
</div>
</div>
</script>
</head>
<body>
<body style="background-color: antiquewhite;">
<div id="pagecontent">
</div>
</body>
</html>
\ No newline at end of file
......@@ -6,4 +6,39 @@ window.onload = function() {
// You shall put your own custom code here.
// window alert() is not allowed to be used in your implementation.
//window.alert("Hello TDDD97!");
};
\ No newline at end of file
document.getElementById("pagecontent").innerHTML = document.getElementById("welcomeview").innerText;
var signupform = document.forms["signupform"]
signupform.addEventListener("submit", function(event) {
event.preventDefault();
inputValidation(event);
})
};
inputValidation = function(event) {
let allInputs = document.forms["signupform"].elements;
for(elem in allInputs) {
if(element.type === "text" && element.value === "") {
console.log("hejejeheh");
return false;
}
}
let emailText = document.forms["loginform"]["email"].value;
if (!validateEmail(emailText)) {
return false;
}
}
function validateEmail(input) {
var validRegex = /\w+@\w+\.\w+/
if (input.value.match(validRegex)) {
alert("Valid email address!");
document.form1.text1.focus();
return true;
} else {
alert("Invalid email address!");
document.form1.text1.focus();
return false;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment