JavaScript Problem for login form
What I need is -
-> User should enter his username, password and his role and has to click submit. All fields are mandatory. And based on the user role, the appropriate login page of the user will be displayed and that should go with radio buttons.
I'm posting my code here, its not working properly. If I come in order by entering username, password, role, its working fine. If I click the radio button first and then clicked submit without entering username and password, I'm getting successful user display page.
Here is my JavaScript code.
<script type="text/javascript"> function validate(login){ if (login.userid.value=="") { alert("Enter Your Username"); login.userid.focus(); return false; } if (login.password.value==""){ alert("Enter Your pass"); login.password.focus(); return false; } if ( ( document.login.site[0].checked == false ) && ( document.login.site[1].checked == false) && ( document.login.site[2].checked == false ) ) { alert ( "Please choose your Role: User1 or User2 or User3" ); return false; } return true; } function sub() { window.location.href = site; } function goTo(URL) { site = URL; } </script>
Here is my HTML login form code.
<form name="login" method="post" action="" > <table> <tr> <td>User ID</td> <td><input type="text" name="userid" size="20" maxlength="50" /></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="password" size="20" maxlength="50" /></td> </tr> <tr> <td>Search Engine : </td> <td><input type="radio" name="site" onchange="if(this.checked){goTo('www.google.com')}"/>User 1<br> <input type="radio" name="site" onchange="if(this.checked){goTo('www.yahoo.com')}"/>User 2<br> <input type="radio" name="site" onchange="if(this.checked){goTo('www.Bing.com')}"/>User 3</td> </tr> <tr><td></td> <td> <input type="button" value="Submit" onclick="validate(login);sub();"> </td> </tr> </table>