Reputation: 29
I've tried running the following E-mail list application on Chrome but can't seem to get the JavaScript to execute. The HTML works fine. Any suggestions or best practices for this application to work? I've included the external JavaScript file too:
<!DOCTYPE html>
<html>
<head>
<meta charset=”UTF-8”>
<title>Join E-mail List</title>
<script src = "index.js"></script>
</head>
<body>
<main>
<h1> Please join our email list</h1>
<form id=”email_form” name=”email_form”
action=”join.html” method=”get”>
<label for=”email_address1”>E-mail Address:</label>
<input type=”text” id=”email_address1” name=”email_address1”>
<span id=”email_address1_error”>*</span><br>
<label for=”email_address2”>Re-enter E-mail Address:</label>
<input type=”text” id=”email_address2” name=”email_address2”>
<span id=”email_address2_error”>*</span><br>
<label for="first_name">Name:</label>
<input type="text" id="first_name" name="first_name">
<span id="first_name_error">*</span><br>
<label> </label>
<input type="button" id="join_list" value="Join Our List">
</form>
</main>
</body>
</html>
enter code here
External JavaScript file (index.js)
/* This application validates a user's entry for joining our E-mail
list
*/
<script>
var $ = function(id) {
return document.getElementById(id);
//This function gets and validates the user entries
var joinList = function() {
var emailAddress1 = $("email_address1").value;
var emailAddress1 = $("email_address2").value;
var firstName = $("first_name").value;
var isValid = true;
//This validates the first entry
if ("email_address1 = "") {
$ ("email_address1_error").firstChild.nodeValue = "This is
required.";
isValid = false;
if (email_address2 = "") {
$ ("email_address2_error").firstChild.nodeValue = "This is
required.";
isValid = false;
if ("first_name = "") {
$ ("first_name_error").firstChild.nodeValue = "First name is
required.";
}
}
}
</script>
Upvotes: 2
Views: 57
Reputation: 243
Content of index.js should be fixed:
var $ = function(id) {
return document.getElementById(id);
//This function gets and validates the user entries
var joinList = function() {
var emailAddress1 = $("email_address1").value;
var emailAddress1 = $("email_address2").value;
var firstName = $("first_name").value;
var isValid = true;
//This validates the first entry
if ("email_address1" == "") {
$ ("email_address1_error").firstChild.nodeValue = "This is required.";
isValid = false;
if ("email_address2" == "") {
$ ("email_address2_error").firstChild.nodeValue = "This is required.";
isValid = false;
if ("first_name" == "") {
$ ("first_name_error").firstChild.nodeValue = "First name is required.";
}
}
}
}
Upvotes: 1