473,608 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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 4141
acoder
16,027 Recognized Expert Moderator MVP
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
Bharat383
93 New Member
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 Recognized Expert Moderator MVP
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
2349
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
1815
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
2320
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 unauthenticated user is browsing the site, and tries to open the UltraSecretContent.aspx page. Forms authentication automatically redirects the user to login.aspx. I would like for login.aspx to display a message that reads, "You must log in before viewing...
3
1746
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
3868
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 IsValidatedUser(UsernameTextBox.Text, PasswordTextBox.Text) Then frmCompanySelect.Show() End If
5
1988
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 entering successful password and clicking ok, login form should go away 4) Main form should then display admin controls
6
1633
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 you use formX as your startup object. I dont want: - to hide or minimaze the login form. - use showdialog.
13
4004
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 visitor logs in, the login form is no longer on the page, but other content is still there. I want to bring focus to the login form using the onLoad in the body tag.....but if the login form does not exist, I do not want to perform this function.
0
1159
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 form and attempt to close it upon loading the next form it closes the entire program. Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click frmMain.Show() End Sub That is...
1
2989
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 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body>
0
8063
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8498
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8478
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8341
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6817
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5476
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3962
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1598
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.