Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The following is a code for a login page. however, I cant seem to get the "onsubmit" to call the function. I've also tried the "onclick" option with submit. Needless to say that that doesn't work either.

Could anyone tell me where am I going wrong?
HTML
<html>
<head>
<title>Login Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function checkinput(form){
    if ((form.LoginId.value===null)||(form.LoginId.value.trim().equals(""))){
        alert('Please enter LoginId');
        form.LoginId.focus();
        return false;
    }
    if ((form.password.value===null)||(form.password.value.trim().equals(""))){
        alert('Please enter Password');
        form.password.focus();
        return false;
    }
}
</script>    
</head>
<body>
    <h1 align="center">Please Enter your Login Credentials</h1>
    <form action="LoginValidator" method="post" name="login"  önsubmit="return checkinput(this);">
        LoginId <input type="text" name="LoginId" maxlength="10"><br /><p>
        LoginRole <select name="LoginRole" size="1">
            <option value="consumer">Consumer</option>
            <option value="administrator" selected>Administrator</option>
            <option value="manager">Manager</option>
            <option value="publicreviewer">Public Reviewer</option>
        </select><br/><p>
        Password <input type="password" name="password" maxlength="20"><br/><p>
        <input type="submit" > <input type="reset">
    </form>
<body>
</html>
Posted
Updated 30-Jun-13 20:47pm
v2
Comments
[no name] 1-Jul-13 9:48am    
Really silly question but have you tried "onsubmit" instead of "önsubmit"?

Have a look at this[^] article.


--Amit
 
Share this answer
 
Comments
Tanmoy_Sen 1-Jul-13 10:22am    
Already checked before posting. No joy.
Hello Tanmoy,

It's the problem in your checkinput function. Please correct it as shown below.
JavaScript
function checkinput(form){
    var fval = form.LoginId.value;
    if (fval===null || fval === "" || "".equals(fval)){
        alert('Please enter LoginId');
        form.LoginId.focus();
        return false;
    }
    fval = form.password.value;
    if (fval===null || fval === "" || "".equals(fval)){
        alert('Please enter Password');
        form.password.focus();
        return false;
    }
}

I also observed that the code you have posted wrongly names onsubmit method as önsubmit (Notice two small dots on top of letter o). Also please properly close the input button tags. The testbed can be found here[^] on JSFiddle.

Regards,
 
Share this answer
 
Comments
Tanmoy_Sen 1-Jul-13 10:22am    
Thanks for the reply, Prasad. Here are the clarifications:
1. Yes, I have noticed the code change. Still, no joy.
2. Yes. I have noticed that onsubmit had 2 dots on top of O. However, this was while copying the code. In my original code, its written properly.
Prasad Khandekar 1-Jul-13 10:31am    
Ok great. Have you tried to play with the JSFiddle link given along with my solution. There you can try changing the javascript code the way you have written, you will find that it does not work. As the conditions evaluate to false.

Regards,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900