The problem I'm facing is that I'm trying to link an external javascript file to my main HTML program but I can't seem to make it happen.
Here is the validation I have in javascript.
function validateFirstName () { //test input for 2-20 characters allowed
var fName = document.getElementById("firstName").value;
var rel = /^[a-zA-Zs'-]{2,20}$/;
if (rel.test(fName)){//if input is valid, update page to show succesful entry
document.getElementById("firstNamePrompt").style.color = "green";
document.getElementById("firstNamePrompt").innerHTML = "valid";
return true;
}
else {//if input is invalid, update page to prompt for new input
document.getElementById("firstNamePrompt").style.color = "Red";
document.getElementById("firstNamePrompt").innerHTML = "<strong>Enter 2-20 characters!</strong>;
return false;
}
}
And here is the HTML.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="Together2.css">
<script type="text/javascript" src="formvalidation10.js"></script>
<title>Sign Up</title>
</head>
<body>
<form action="#">
<div id="fullpage">
<h1>SIGN UP WITH US</h1>
<BR/>
<img src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg"/>
<BR/>
<BR/>
<table>
<tr>
<td class="label_col">First Name:</td>
<td class="input_col"><input name="firstName" id="firstName" type="text" onblur="validateFirstName();"></td>
<td class="feedback_col"><span id="firstNamePrompt"> </span></td>
</tr>
I've looked to similar answers but I still can't find the problem. Could you please check it? Thank you in advance.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…