473,387 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Login form: enable disabled login button when username/password have values

I have to come up with a user authenication page the logs the user in and also gives them access to do the right things. without using server side scripting. Just javacript and access. I have attached the code and the access file and have got started on a few things.
I first need to create a login page with the fields username and password have that check the access database and then proceed it to a page to do the following depending on the user access. For The Login button to even be enabled the username and password must have a value in it; I have no idea how to do that

Add A User [No duplicate Users]
Modify A User
- Admin can change anyone
- Power User can change only themselves
and everyone else except admin
- regular user can only change themselves
Delete A User
-Admin can delete anyone
Password Length [9-20 Characters]
Display The current person logged in person's info
Display all users

Groups:
Administrative - Has the ability to change everything
Power - Can change/modify everyone's informantion EXCEPT administrative group people
Regular - Can modify themselves only.

Only administrator and power user should be able to add a user

Only admin can delete users

Again it's supposed to connect with Access database and need to use javascript. I attached the file and code.Access 2007 File Thanks =).

HTML Page
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.     <title>JavaScript Example 2</title>
  4.     <script type="text/javascript" src="JScriptDB.js">
  5.  
  6.     </script>
  7. </head>
  8. <body>
  9.  
  10. <form name="student" method="get" action="" onSubmit="return false;">
  11.  
  12. <p>Enter student's first name: <input type="text" name="studentfn" /><br />
  13.   Enter student's last name: <input type="text" name="studentln" /><br />
  14.   Enter student's ID: <input type="text" name="studentid" /><br />
  15.   User Name:  <input type="text" name="usr1" id="usr1" /><br/>
  16. Password*: <input type="password" name="pswd1" id="pswd1" /><br /> 
  17. Date Of Birhth:  <input type="text" name="dob1" id="dob1" /><br/>
  18.  </p>
  19. <p>
  20.   <input type="button" id="Display" onClick="Display()" value="Display All Records" />
  21.     <input type="button" id="Update" onClick="updateStudent()" value="Update Student" />
  22.       <input type="button" id="Delete" onClick="deleteStudent()" value="Delete Record" />
  23.         <input type="button" id="Insert" onClick="insertStudent()" value="Insert Record" />
  24.           <input type="button" id="Display" onClick="DisplayUser()" value="Display User Record" />
  25. </p>
  26.  
  27. </form>
  28.  
  29. </body>
  30. </html>
  31.  
Javascript
Expand|Select|Wrap|Line Numbers
  1. //declare variables
  2.  
  3. var adOpenDynamic =2;
  4. var adLockOptimistic =3;
  5. var strDB_Path = "C:\Temp\\cst2309.accdb"; //MS access db path
  6. var conn_str = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strDB_Path; // MS 2007 Provider String
  7.  
  8. var conn_str11 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strDB_Path; // MS 2003 Provider String
  9.  
  10.  
  11. function AdoDB(strADO)
  12. {
  13.     if(window.ActiveXObject)
  14.     {
  15.         return new ActiveXObject(strADO);
  16.     }
  17.     else
  18.     {
  19.         return ActiveXObject(strADO);
  20.     }
  21. }
  22.  
  23. function DisplayUser()
  24. {
  25.     var conn = AdoDB("ADODB.Connection");
  26.     var strSQL = "Select * from Student where usr ='"+ usr1 + "' and pswd = '"+ pswd1 +"'";
  27.  
  28.     conn.open(conn_str,"",""); //open my db connection
  29.  
  30.     // declare my dataset
  31.     var dsStudent = new ActiveXObject("ADODB.Recordset");
  32.  
  33.     dsStudent.open(strSQL, conn, adOpenDynamic, adLockOptimistic);
  34.  
  35.     var strHTML ="";
  36.     strHTML ="<table cellpadding=0 cellspacing=0 border=1 width='100%' align=center>";
  37.     strHTML +="<tr><td align=center colspan=4><b>Student Records</b></td></tr>";
  38.  
  39.     if(!dsStudent.bof)
  40.     {
  41.         dsStudent.MoveFirst();
  42.         while(!dsStudent.eof)
  43.         {
  44.             strHTML += "<tr>";
  45.             strHTML += "<td><Font face='tahoma'>" + dsStudent.fields(0) +"</font></td>";
  46.             strHTML += "<td><Font face='tahoma'>" + dsStudent.fields(1) +"</font></td>";
  47.             strHTML += "<td><Font face='tahoma'>" + dsStudent.fields(2) +"</font></td>";
  48.             strHTML += "<td><Font face='tahoma'>" + dsStudent.fields(3) +"</font></td>";
  49.             strHTML += "<td><Font face='tahoma'>" + dsStudent.fields(4) +"</font></td>";
  50.             strHTML += "<td><Font face='tahoma'>" + dsStudent.fields(5) +"</font></td>";
  51.             strHTML += "<td><Font face='tahoma'>" + dsStudent.fields(6) +"</font></td>";
  52.             strHTML += "</tr>";
  53.             dsStudent.MoveNext();
  54.         }//close while
  55.     }// close if statement
  56.     else
  57.     {
  58.         strHTML += "<tr colspan=4><td align=center><font color=red>No Records :(</font></td></tr>";
  59.     }//close else
  60.     strHTML = "</table>";
  61.     document.write(strHTML);
  62. }// close Display
  63.  
  64. function Display()
  65. {
  66.     var conn = AdoDB("ADODB.Connection");
  67.     var strSQL = "Select * from Student";
  68.  
  69.     conn.open(conn_str,"",""); //open my db connection
  70.  
  71.     // declare my dataset
  72.     var dsStudent = new ActiveXObject("ADODB.Recordset");
  73.  
  74.     dsStudent.open(strSQL, conn, adOpenDynamic, adLockOptimistic);
  75.  
  76.     var strHTML ="";
  77.     strHTML ="<table cellpadding=0 cellspacing=0 border=1 width='100%' align=center>";
  78.     strHTML +="<tr><td align=center colspan=4><b>Student Records</b></td></tr>";
  79.  
  80.     if(!dsStudent.bof)
  81.     {
  82.         dsStudent.MoveFirst();
  83.         while(!dsStudent.eof)
  84.         {
  85.             strHTML += "<tr>";
  86.             strHTML += "<td><Font face='tahoma'>" + dsStudent.fields(0) +"</font></td>";
  87.             strHTML += "<td><Font face='tahoma'>" + dsStudent.fields(1) +"</font></td>";
  88.             strHTML += "<td><Font face='tahoma'>" + dsStudent.fields(2) +"</font></td>";
  89.             strHTML += "<td><Font face='tahoma'>" + dsStudent.fields(3) +"</font></td>";
  90.             strHTML += "<td><Font face='tahoma'>" + dsStudent.fields(4) +"</font></td>";
  91.             strHTML += "<td><Font face='tahoma'>" + dsStudent.fields(5) +"</font></td>";
  92.             strHTML += "<td><Font face='tahoma'>" + dsStudent.fields(6) +"</font></td>";
  93.             strHTML += "</tr>";
  94.             dsStudent.MoveNext();
  95.         }//close while
  96.     }// close if statement
  97.     else
  98.     {
  99.         strHTML += "<tr colspan=4><td align=center><font color=red>No Records :(</font></td></tr>";
  100.     }//close else
  101.     strHTML = "</table>";
  102.     document.write(strHTML);
  103. }// close Display
  104.  
  105.  
  106. function updateStudent() {
  107.     var fn = document.getElementById("studentfn").value;
  108.     var ln = document.getElementById("studentln").value;
  109.     var studid = document.getElementById("studentid").value;
  110.  
  111.     var strSQL = "update Student set fname = '" + fn + "' ,lname ='" + ln + "' where studentid =" + studid;
  112.     alert("SQL statement: " + strSQL);
  113.  
  114.     var conn = AdoDB("ADODB.Connection");
  115.  
  116.     conn.open(conn_str,"",""); //open my db connection
  117.  
  118.     // declare my dataset
  119.     var dsStudent = new ActiveXObject("ADODB.Recordset");
  120.  
  121.     dsStudent.open(strSQL, conn, adOpenDynamic, adLockOptimistic);
  122.  
  123.     alert("updated completed");
  124. }// close updateStudent
  125.  
  126. function deleteStudent()
  127. {
  128. //    var fn = document.getElementById("studentfn").value;
  129. //    var ln = document.getElementById("studentln").value;
  130.     var studid = document.getElementById("studentid").value;
  131.  
  132.     var strSQL = "delete Student where studentid =" + studid;
  133.     alert("SQL statement: " + strSQL);
  134.  
  135.     var conn = AdoDB("ADODB.Connection");
  136.  
  137.     conn.open(conn_str, "", ""); //open my db connection
  138.  
  139.     // declare my dataset
  140.     var dsStudent = new ActiveXObject("ADODB.Recordset");
  141.  
  142.     dsStudent.open(strSQL, conn, adOpenDynamic, adLockOptimistic);
  143.  
  144.     alert("deleted completed");
  145.  
  146. }// close deleteStudent
  147.  
  148. function insertStudent()
  149. {
  150.     var fn = document.getElementById("studentfn").value;
  151.     var ln = document.getElementById("studentln").value;
  152.     var studid = document.getElementById("studentid").value;
  153.     var dobv = document.getElementById("dob1").value;
  154.  
  155.     var strSQL = "insert into Student(fname, lname,dob) values('" + fn + "','" + ln + "','" + dobv +"')";
  156.     alert("SQL statement: " + strSQL);
  157.  
  158.     var conn = AdoDB("ADODB.Connection");
  159.  
  160.     conn.open(conn_str, "", ""); //open my db connection
  161.  
  162.     // declare my dataset
  163.     var dsStudent = new ActiveXObject("ADODB.Recordset");
  164.  
  165.     dsStudent.open(strSQL, conn, adOpenDynamic, adLockOptimistic);
  166.  
  167.     alert("insert completed");
  168. }// close insertStudent
  169.  
  170. function LoginPerson()
  171. {
  172.  
  173. var conn = AdoDB("ADODB.Connection");
  174. var strSQL = "Select * from Student where usr ='"+ usr1 + "' and pswd = '"+ pswd1 +"'";
  175.  
  176.     conn.open(conn_str,"",""); //open my db connection
  177.  
  178.     // declare my dataset
  179.     var dsStudent = new ActiveXObject("ADODB.Recordset");
  180.  
  181.     dsStudent.open(strSQL, conn, adOpenDynamic, adLockOptimistic);
  182.  
  183.     alert("Logging In");
  184.  
  185.  var strHTML ="";
  186.     strHTML ="<table cellpadding=0 cellspacing=0 border=1 width='100%' align=center>";
  187.     strHTML +="<tr><td align=center colspan=4><b>Student Records</b></td></tr>";
  188.  
  189.     if(!dsStudent.bof)
  190.     {
  191.         dsStudent.MoveFirst();
  192.         while(!dsStudent.eof)
  193.         {
  194.             strHTML += "<tr>";
  195.             strHTML += "<td><Font face='tahoma'>" + dsStudent.fields(0) +"</font></td>";
  196.             strHTML += "<td><Font face='tahoma'>" + dsStudent.fields(1) +"</font></td>";
  197.             strHTML += "<td><Font face='tahoma'>" + dsStudent.fields(2) +"</font></td>";
  198.             strHTML += "<td><Font face='tahoma'>" + dsStudent.fields(3) +"</font></td>";
  199.             strHTML += "<td><Font face='tahoma'>" + dsStudent.fields(4) +"</font></td>";
  200.             strHTML += "<td><Font face='tahoma'>" + dsStudent.fields(5) +"</font></td>";
  201.             strHTML += "<td><Font face='tahoma'>" + dsStudent.fields(6) +"</font></td>";
  202.             strHTML += "</tr>";
  203.             dsStudent.MoveNext();
  204.         }//close while
  205.     }// close if statement
  206.     else
  207.     {
  208.         strHTML += "<tr colspan=4><td align=center><font color=red>No Records :(</font></td></tr>";
  209.     }//close else
  210.     strHTML = "</table>";
  211.     document.write(strHTML);
  212. }// close Login
Dec 5 '10 #1
3 4122
acoder
16,027 Expert Mod 8TB
Keep your login button disabled:
Expand|Select|Wrap|Line Numbers
  1. <input type="button" ... disabled="disabled">
Then you need some event to trigger the change. One event is the onchange event on the username and password text boxes, e.g.
Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="username" ... onchange="enableButton()">
where the function would enable the button if both the text boxes had values in them. To enable a button, set the disabled property to false:
Expand|Select|Wrap|Line Numbers
  1. btn.disabled = false;
Dec 21 '10 #2
Expand|Select|Wrap|Line Numbers
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head>
  3. <title>Login form </title>
  4. <script type="text/javascript">
  5.     function display_submit()
  6.     {
  7.             if((document.getElementById("uname").value != "") && (document.getElementById("pwd").value != ""))
  8.             {
  9.                 document.getElementById("submit_button").disabled = false;
  10.             }
  11.             else
  12.             {
  13.                 document.getElementById("submit_button").disabled = true;
  14.             }
  15.     }
  16. </script>
  17. </head>
  18. <body>
  19. <form name="form1">
  20.     <table width="300" cellspacing="10">
  21.         <tr>
  22.                 <th>Username</th>
  23.                 <td>
  24.                         <input type="text" name="uname" value="" id="uname" onblur="display_submit()"/>
  25.                 </td>
  26.         </tr>
  27.         <tr>
  28.                 <th>Password</th>
  29.                 <td>
  30.                     <input type="password" name="password" value="" id="pwd"  onblur="display_submit()"/>
  31.                 </td>
  32.         </tr>
  33.         <tr>
  34.                 <td colspan="2" align="center">
  35.                         <input type="submit" name="submit_button" id="submit_button" value="LOG IN" disabled="disabled"/>
  36.                 </td>
  37.         </tr>
  38.     </table>
  39. </form>
  40. </body>
  41. </html>
May 17 '12 #3
acoder
16,027 Expert Mod 8TB
onchange (triggered on a change) makes more sense that onblur.
May 23 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: John Wolrehammer | last post by:
After the user login in i want to close the login form. I can close it but it also closes the whole application. Can anyone help.
5
by: JPSutor | last post by:
I have a login form, that if successfully answered, launches another form. The problem is that the login form remains even after I show the main form. How do I get rid of the login form?
4
by: David Krussow | last post by:
Just wondering if/how it would be possible to display a variable string on the login form - where the string varies depending on the form the user attempted to access. To clarify, an...
3
by: Agnes | last post by:
My login form will call a main form with menu in my button_OK click event >dim frmMain as new mainform >frmMain.show() >Me.dispose() The login form didn't close by itself, Please help.. Thanks
3
by: Bob | last post by:
I haver a user login form (winforms app using vs2005 in VB.NET). After succesfull validayion of user I want to open a first form and close the loging form that was used, If I write If...
5
by: Ronald S. Cook | last post by:
It's been longer that I remember since writing windows (not web) apps. 1) I want to load a main form 2) User clicks login button which brings up login form (on top of main form) 3) Upon...
6
by: jt | last post by:
The program i have has login form. After a user has loged in, formX is loaded and i want to dispose all the forms that where used before (login form). so the result should be the same as when...
13
by: knot2afrayed | last post by:
I am trying to fix error- object does not exist- I want it possible to allow object not to exist. I am writing a script on a page that may or may not include a login form. For example-after a...
0
by: Rinoa | last post by:
I'm developing a program with a login form. I want the login in form to be the first form that loads, and I want it to close itself when the main CP loads. However, when I set frmLogIn as the startup...
1
by: naharol | last post by:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@page import="java.sql.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.