Q:

Javascript validation error

I have written the following code in html and the javascript file is also embedded below
<!DOCTYPE html>
<meta charset="utf-8">
<HTML>
<head>
<link rel="stylesheet" href="admin.css"/>
<script type="text/javascript" src="common.js"></script>
</head>
<BODY>
<div class="adminnav" id="adminnav">
<ul>
<li><a href="#">Insert</a>
<ul>
<li><a href="addcourse.html">Insert Course</a></li>
<li><a href="addstudent.html">Insert Student</a></li>
<li><a href="addteacher.html">Insert Teacher</a></li>
<li><a href="addsubject.html">Insert Subject</a></li>
</ul>
</li>
</ul>
</div>
<div class="addcourse" >
<form name="course" onSubmit='return validcourse()' method="POST">
Course Name:
  <input type="text" name="coursename" id="cname" /><br>
Duration:<input type="text" name="cd"/>
<br>
Course Id:<input name="cid" type="text" /><br>
<input  type="submit" value="submit" name="submit"><input type="reset" name="coursereset">
</form>
</div>
</BODY>
</HTML>

common.js
function validcourse()
{
    var course_name=document.course.coursename;
    var course_duration=document.course.cd;
    var course_id=document.course.cid;

    if(course_name_valid(course_name))
    {
        {
            if(course_duration_valid(course_duration))
            {
                if(course_id_valid(cid))
                {
                }
            }
        }
    }

}

function course_name_valid(course_name)
{
    var letters=/^[A-Za-z]+$/;
    if(course_name.value.match(letters))
    {
        return true;
    }
    else
    {
        alert("Course name must have alphabets only");
        course_name.focus();
        return false;

    }
}

function course_duration_valid(course_duration)
{
    var letters=/^[1-9]+$/;
    if(cd.value.match(letters))
    {
        return true;
    }
    else
    {   
        alert("Course Duration can have numbers only");
        course_duration.focus();    
        retun false;
    }   

}

function course_id_valid(course_id)
{
    var letters=/^[0-9a-zA-z]+$/;
    if(course_id.value.match(letters))
    {
        return true;
    }
    else
    {
        alert('Course ID must have character and numeric values only');
        course_id.focus();
        return false;           
    }
}

My problem is that nothing is happening no error messages are given.
Error messages are given only for course name but not for course duration and course id?
Here is a link to jsfiddle http://jsfiddle.net/amolkarale/aTfq6/1/

A:

You are not returning anything from validcourse.  Add a return true; and return false; in there, to either let the submission continue or stop the submission from happening: 
function validcourse()
{
    var course_name=document.course.coursename;
    var course_duration=document.course.cd;
    var course_id=document.course.cid;

    if(course_name_valid(course_name))
    {
        {
            if(course_duration_valid(course_duration))
            {
                if(course_id_valid(cid))
                {
                    return true;
                }
            }
        }
    }
    return false;

}

