I'm using IE.
Let's start with the html document so I can show that the linking is done correctly.
HTML Code:
<html>
<head>
<title>title</title>
<link href="the.css" rel="stylesheet" type="text/css" />
<script src="the.js">
</script>
</head>
<body>
<!-- skipping some code here that has nothing to do with the form -->
<div id="main_div">
<form>
<br /><br /><br />
<table>
<tr><td>Name: </td><td><input type="text" name="Name: " id="name"></td></tr>
<tr><td>Age: </td><td><textarea name="Age: " rows="1" cols="3" id="age"></textarea></td></tr>
<!-- Skipping some more inputs -->
<input type="button" value="Send" onclick="formval()">
</form>
</div>
</body>
</html>
And now the.js
Code:
function formval() {
var numbers = /^[0-9]+$/;
var letters = /^[a-zA-Z]+$/;
if (document.getElementById('name').value.match(letters)) {
return true;
}
else {
alert('Please Fill in your name');
document.getElementById('name').focus();
return false;
}
/* The above part is what ain't working */
else if (document.getElementById('age').value.match(numbers)){
return true;
}
else {
alert('Please fill in your age');
document.getElementById('age').focus();
return false;
}
}
The second check(numbers) works perfectly if I were to comment out the first check(letters).
Bookmarks