Skip to content

Commit fe2bb83

Browse files
init
0 parents  commit fe2bb83

3 files changed

Lines changed: 91 additions & 0 deletions

File tree

css/style.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
* {font-family: sans-serif;}
2+
3+
#form {line-height: 2;}
4+
5+
#form input {margin-left: 25px;}
6+
7+
#form input[id="phone"] { margin-left: 10px;}
8+
9+
#form textarea {
10+
margin-left: 2px;
11+
margin-top: 10px;
12+
}
13+
14+
.warning {
15+
color: red;
16+
}

index.html

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>mwForm</title>
6+
<link rel="stylesheet" href="css/style.css">
7+
</head>
8+
<body>
9+
<div id="pre-form">
10+
<h2>We'd love to hear your thoughts!</h2>
11+
</div>
12+
<div class="form-container">
13+
<form id="form" name="form">
14+
15+
<h3>Contact Us Here:</h3>
16+
<p id="message"></p>
17+
18+
<label>Name:</label>
19+
<input id="name" placeholder="Name" type="text"><br>
20+
<label>Email:</label>
21+
<input id="email" placeholder="Email" type="email"><br>
22+
<label>Number:</label>
23+
<input id="phone" placeholder="10 digit phone number." type="tel"><br>
24+
<label>Message:</label>
25+
<textarea id="message" placeholder="Your thoughts here :)"></textarea><br>
26+
<input id="submit" type="button" value="Send It!">
27+
28+
</form>
29+
</div>
30+
31+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
32+
<script type="text/javascript" src="js/app.js"></script>
33+
</body>
34+
</html>
35+

js/app.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// This makes sure the document exists before your code tries to manipulate it.
2+
$(document).ready(function () {
3+
4+
// Attach an event handler function to the submit button.
5+
$("#submit").on("click", function () {
6+
// Store references to values of inputs
7+
var name = $("#name");
8+
var email = $("#email");
9+
var phone = $("#phone");
10+
var message = $("#message");
11+
// Store all values of required inputs into array
12+
var reqArray = [name, email, phone];
13+
14+
// Loop through all required elements
15+
for (var i = 0; i < reqArray.length; i++) {
16+
// Check value of required item to ensure it is not empty
17+
if (reqArray[i].val() === '') {
18+
// target message paragraph to display message user to double check their inputs
19+
message.text("Please fill out required fields.");
20+
// add css class to message paragraph to alter its styling
21+
message.addClass('warning');
22+
// target the associated label that exists adjacent to input, add class from stylesheet to alter its appearance
23+
reqArray[i].prev("label").addClass('warning');
24+
} else {
25+
// if value is not empty, ensure the warning class is removed
26+
reqArray[i].prev("label").removeClass('warning');
27+
}
28+
}
29+
30+
// if all labels on page do not have warning class, 'submit' form and notify user of success
31+
if (!$("label").hasClass("warning")) {
32+
// alter the content of the header on page with custom string
33+
$("#pre-form > h2").html("Thanks for your feedback");
34+
// target the form and remove it from the DOM
35+
$("#form").remove();
36+
}
37+
38+
})
39+
40+
});

0 commit comments

Comments
 (0)