Hello DaniWeb Community, I've recently been working on a simple input page for user to key in and then, returns an error if it doesn't match the required input type. However, I've been trying to get them working but they don't.
I've 2 pages (author.html & book.html) which send their input values to an external validating page (validation.js). I would appreciate your effort if you could show me a little guidance on how to make them working
Author.html
<html>
<head>
<link rel="stylesheet" href="sitestyle.css" type="text/css" />
<script src="validation.js"></script>
<title>Author page!</title>
</head>
<body>
<h1>Please enter your Author ID and Author Name into the field provided.</h1>
<form name="authorform" onSubmit="return author();">
Author ID :
<br>
<input type="text" name="authorID"/>
<p>
Author Name :
<br>
<input type="text" name="authorName"/>
<p>
<input type="submit" name="Save" value="Save">
<input type="reset" name="Cancel" value="Cancel">
</form>
</body>
</html>
Book.html
<html>
<head>
<link rel="stylesheet" href="sitestyle.css" type="text/css">
<script src="validation.js"></script>
<title>Book page</title>
</head>
<body>
<h1>Please enter your book details below.</h1>
<form name="fbook" onSubmit="return book();">
<p>Please enter your book ID :
<br>
<input type="text" name="bookid"/>
</p>
<p>Please enter your book title :
<br>
<input type="text" name="booktitle"/>
</p>
<p>Please enter your Author ID :
<br>
<input type="text" name="authorID"/>
</p>
<p>Please enter your book Year :
<br>
<input type="text" name="bookyear"/>
</p>
<input type="submit" name="Save" value="Save">
<input type="reset" name="Cancel" value="Cancel">
</form>
</body>
</html>
Validation.js
function author(){
// variable declarations for author
var aid = document.authorform.authorID;
var authorName = document.authorform.authorName;
// main functions
if(validnum(aid))
{
if(allLetter_author(authorName))
{
}
}
// function validnum(aid) for author()
function validnum(aid){
var numbers = /^[0-9]+$/;
if(aid.value=""){
alert("Please enter Author ID!");
aid.value.select();
aid.value.focus();
return false;
}
if (aid.value.match(numbers)){
return true;
}
else {
alert("Please insert only positive numeric value!");
aid.value.select();
aid.value.focus();
return false;
}
return true;
}
// function allLetter(authorName) for author()
function allLetter_author(authorName)
{
var letters = /^[A-Za-z]+$/;
if(authorName.value.match(letters))
{
return true;
}
else {
alert("Author Name must have alphabet characters only");
authorName.focus();
return false;
}
}
}
// function book
function book()
{
// variable declaraction for book
var bid = document.fbook.bookid;
var btitle = document.fbook.booktitle;
var baid = document.fbook.authorID;
var byear = document.fbook.bookyear;
var numbers = /^[0-9]+$/;
if(bookvalid())
{
if(allLetter_book(btitle))
{
}
}
//function bookvalid() for book()
function bookvalid()
{
if(bid.value==""){
alert("Please insert the Book ID!");
bid.focus();
return false;
}
if(bid.value.match(numbers))
{
return true;
}
else
{
alert("Please insert only positive numeric value!");
bid.focus();
return false;
}
if(byear.value=="")
{
alert("Please insert the Book Year!");
byear.focus();
return false;
}
if(byear.value.match(numbers))
{
return true;
}
else
{
alert("Please insert only positive numeric value!");
byear.focus();
return false;
}
}
// function allLetter(btitle) for book()
function allLetter_book(btitle)
{
var letters = /^[A-Za-z]+$/;
if(btitle.value.match(letters))
{
return true;
}
else {
alert("Book title must have alphabet characters only");
btitle.focus();
return false;
}
}
}
External css (just in case)
/* CSS Document */
body {
background-color: lightblue;
font-family:century gothic;
}
h1 {
color:red;
}