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;
}

Sorry for not including the required information on the input type.

-Author Name is alphabet
-AuthorID is valid positive numbers
-booktitle is alphabet
-bookID & bookYear are valid positive numbers

You post your code and what it should do, but you didn't say what the problem is.

What dificulties are you having?

I couldn't manage to make them to pop up the result of validation of user inputs. Rather, it doesn't appear for some reason...

I've finally managed to figure it out! Here's the new validation code and a bit tweaking to the Author.html & Book.html.

Nonetheless, thanks again to all who spent some time looking at my messy codes :)

// function author()
function author()
{
numbers = /^[0-9]+$/;
characters = /^[A-Za-z]+$/;

    // beginning of authorID if loop validation
    if(document.form.authorID.value.length == 0 )
    {
        alert("Please do enter a value to Author ID!");
        document.form.authorID.select();
        document.form.authorID.focus();
        return false;
    }
    else
    { 
        if(document.form.authorID.value.match(numbers))
        {
        }
        else 
        {
            alert("Only positive numbers allowed!");
            document.form.authorID.select();
            document.form.authorID.focus();
            return false;
        }
    } // end of authorID if loop validation

    // beginning of authorName if loop validation 
    if(document.form.authorName.value.length == 0 )
    {
        alert("Please do enter a value to Author Name!");
        document.form.authorName.select();
        document.form.authorName.focus();
        return false;
    }
    else
    { 
        if(document.form.authorName.value.match(characters))
        {
        }
        else 
        {
            alert("Only alphabets allowed!");
            document.form.authorName.select();
            document.form.authorName.focus();
            return false;
        }
    } // end of authorName if loop validation
} // end of author()

// function book()
function book()
{
numbers = /^[0-9]+$/;
characters = /^[A-Za-z]+$/;

    // beginning of bookID if loop validation
    if(document.fbook.bookID.value.length == 0 )
    {
        alert("Please do enter a value to Book ID!");
        document.fbook.bookID.select();
        document.fbook.bookID.focus();
        return false;
    }
    else
    { 
        if(document.fbook.bookID.value.match(numbers))
        {
        }
        else 
        {
            alert("Only positive numbers allowed!");
            document.fbook.bookID.select();
            document.fbook.bookID.focus();
            return false;
        }
    } // end of bookID if loop validation

    // beginning of booktitle if loop validation
    if(document.fbook.booktitle.value.length == 0 )
    {
        alert("Please do enter a value to Book Title!");
        document.fbook.booktitle.select();
        document.fbook.booktitle.focus();
        return false;
    }
    else
    { 
        if(document.fbook.booktitle.value.match(characters))
        {
        }
        else 
        {
            alert("Only alphabets allowed!");
            document.fbook.booktitle.select();
            document.fbook.booktitle.focus();
            return false;
        }
    } // end of booktitle if loop validation

    // beginning of book author ID if loop validation
    if(document.fbook.authorID.value.length == 0 )
    {
        alert("Please do enter a value to Book Author ID!");
        document.fbook.authorID.select();
        document.fbook.authorID.focus();
        return false;
    }
    else
    { 
        if(document.fbook.authorID.value.match(numbers))
        {
        }
        else 
        {
            alert("Only positive numbers allowed!");
            document.fbook.authorID.select();
            document.fbook.authorID.focus();
            return false;
        }
    } // end of book author ID if loop validation

    // beginning of book year if loop validation
    if(document.fbook.bookyear.value.length == 0 )
    {
        alert("Please do enter a value to Book Year!");
        document.fbook.bookyear.select();
        document.fbook.bookyear.focus();
        return false;
    }
    else
    { 
        if(document.fbook.bookyear.value.match(numbers))
        {
        }
        else 
        {
            alert("Only positive numbers allowed!");
            document.fbook.bookyear.select();
            document.fbook.bookyear.focus();
            return false;
        }
    } // end of book year if loop validation


} // end of book()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.