473,587 Members | 2,476 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using the Enter Key to trigger a password button

5 New Member
I am very new to HTML and I am making a web page for my father. I am trying to make a password protected page and I got that working but it will only advance to the password protected page if they click the log in button after entering the password, it will not work if they click enter I was wondering how to make this possible. Also is there a way when the password is entered that it only comes up with circles not the actual password?

here is the code:

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/javascript">
  2. <!--- PASSWORD PROTECTION SCRIPT
  3.  
  4. function TheLogin() {
  5.  
  6. var password = '******'; 
  7. //this is where I place the password to use
  8.  
  9. if (this.document.login.pass.value == password) {
  10.   top.location.href="http://www.*******";
  11. }
  12. else {
  13.   location.href="http://www.*******";
  14.   }
  15. }
  16.  
  17. // End hiding --->
  18. </script>
  19.  
  20. </head>
  21. <body> 
  22. <div id="container"> 
  23. <div style="margin-left:0px;"> 
  24. <div style="margin-right:50px;">
  25. <center>
  26. Enter your password:<br>
  27. <form name="login" style="margin: 0px">
  28. <INPUT TYPE="text" NAME="pass" size="17" onKeyDown="if(event.keyCode==13) event.keyCode=9;" style="width: 152px; margin: 5px;"><br>
  29. <input type="button" value="Login" style="width : 150px; margin: 3px" onClick="TheLogin(this.form)">
  30. </form>
  31. </center>
  32.  
Please help if you have time
Dec 2 '10 #1
9 2835
Dormilich
8,658 Recognized Expert Moderator Expert
a) real password protection must be done serverside. anyone looking at your source code will see the password.

b) for the password field use <input type="password" >
Dec 2 '10 #2
Adam Wolfe
5 New Member
a) real password protection must be done serverside. anyone looking at your source code will see the password.

what do you mean by serverside ? How is this possible what would I have to edit ? Also is it very hard to make the enter key on the keyboard submit the password field ?

As I am very new to HTML all the google searches I am doing on this topic are hard to follow I do not know what to put where I did find this little bit of code though do i need to use something like this:
Expand|Select|Wrap|Line Numbers
  1.    1. <script>  
  2.    2.   
  3.    3.         function clickButton(e, buttonid){   
  4.    4.   
  5.    5.           var evt = e ? e : window.event;  
  6.    6.   
  7.    7.           var bt = document.getElementById(buttonid);  
  8.    8.   
  9.    9.           if (bt){   
  10.   10.   
  11.   11.               if (evt.keyCode == 13){   
  12.   12.   
  13.   13.                     bt.click();   
  14.   14.   
  15.   15.                     return false;   
  16.   16.   
  17.   17.               }   
  18.   18.   
  19.   19.           }   
  20.   20.   
  21.   21.         }  
  22.   22.   
  23.   23.     </script>  
  24.  
Dec 2 '10 #3
Dormilich
8,658 Recognized Expert Moderator Expert
what do you mean by serverside ?
on the webserver. there are different ways to do that.
- on an Apache webserver, you can create a .htaccess file that asks the client for verification (username & password)
- you can also use any serverside programming language to write a script that validates a given username and password and thus grants access to webpages.

usually hitting the enter key triggers the submit button to be "pressed", although you can use JavaScript to capture this event.
Dec 2 '10 #4
Adam Wolfe
5 New Member
ok I will read up about the .htaccess files. Is the JavaScript code i posted above what I would use to "capture" that event ? I just do not know what to place where.
Dec 2 '10 #5
Dormilich
8,658 Recognized Expert Moderator Expert
Is the JavaScript code i posted above what I would use to "capture" that event ?
yes and no.

on the one hand side, checking for keycode 13 is what you need to do, on the other hand side, the function will not work due to the event not being registerd and the buttonid being undefined.
Dec 2 '10 #6
Adam Wolfe
5 New Member
What would I have to do to change the code to be functional ?
Dec 2 '10 #7
Dormilich
8,658 Recognized Expert Moderator Expert
you know how event handling (in general) works?
Dec 2 '10 #8
Adam Wolfe
5 New Member
I actually don't know how event handling works
Dec 2 '10 #9
Dormilich
8,658 Recognized Expert Moderator Expert
ok, before going back to your problem, I’ll talk a bit about Events, as this is necessary to understand the solution.

How does HTML code get into JavaScript?

the HTML source code is translated for JavaScript so that it can alter the HTML’s appearance. it is of utmost importance to understand this, otherwise the HTML/JavaScript interaction stays a mystery.
when the browser loads the HTML source code, it internally creates a representation of the code. thus each tag and each attribute and each text gets assigned a special object. the mechanism responsible for that is called DOM (Document Object Model). so what you have access to in JavaScript is not the HTML itself, but its object representation in the browser.

it is important to understand that an HTML attribute is not the same as the HTML attribute’s object equivalent in JavaScript.

rule of thumb: in JavaScript, everything is an object (and I mean everything).

What is an Event?

an event is some kind of action that occurs in the document, for example a click, a load, a mouse moving, all kinds of stuff. the events that are possible are standardised by the W3C in the DOM .

How does an Event work in JavaScript?

this is implemented in JavaScript through the use of the Event object, i.e. the user’s action (e.g. a click) is translated/modelled into a native JavaScript object (named "Event"). then this object travels through the document tree (resp. its objects that represent a HTML element) where it can trigger programmatic actions. these events are created automatically, you don’t have to do anything there.

How do I make an Event trigger something?

this is called Event Handling (making an event do something useful). the basic idea is that you wait for an event object to pass by. therefore you add a programming instruction to the object (the HTML element object) where the event passes through.

this can be done in several ways:
* inline javascript: only do that when there is no other possibility.

* DOM-0 Events: before there was a standard, browser vendors invented a way to handle events. this is done by using event properties (a property is part of an object, it is not the same as an HTML attribute). each HTML element object in JavaScript can be assigned an event property consisting of "on" + the event name (e.g. "click" => onclick). to this property a function variable must be passed. additionally, this function may only contain a single parameter that is the Event object.
Expand|Select|Wrap|Line Numbers
  1. function event_handler(evt)
  2. {
  3.     alert("this is a " + evt.type + " event");
  4. }
  5.  
  6. // div being a <div> element in JavaScript
  7. // note the missing parentheses
  8. div.onclick = event_handler;
according to the standard, when the click event reaches that <div> element, the function event_handler is executed with the click event object as parameter. additionally, the scope of the function changes. until now, the function belonged to the global scope, but now it is owned by the executing element object. this manifests in the system variable this, which changes from window to div (a very convenient way to access the current element!)

note: IE does not adhere to the standard. instead of passing an event through the document tree, it provides the event object as a global, only triggering the function to execute. (you already used the work-around for that)

* DOM-2: eventually, the W3C released a standard how Events should work. this brought along some very convenient features:
- you can assign multiple event handlers
- the event travels up and down in the document tree (bubbling and capturing)
- you can influence the event flow (canceling the event, preventing the default action an event would usually trigger).

Expand|Select|Wrap|Line Numbers
  1. function event_handler_1(evt)
  2. {
  3.     alert("I’m a " + this.tagName + " element");
  4.     // cancel the event
  5.     evt.stopPropagation();
  6. }
  7.  
  8. function event_handler_2(evt)
  9. {
  10.     alert("this is a " + evt.type + " event");
  11. }
  12. // catch event when it goes down in the document tree
  13. div.addEventListener("click", event_handler_1, true);
  14. // catch event when it goes up in the document tree
  15. // this is the same direction as in DOM-0
  16. div.addEventListener("click", event_handler_2, false);
  17.  
  18. /* you may guess what actions will happen … */
and now the bad news: IE doesn’t implement that at all. MS decided to go its own totally different way. there is also no easy work-around to make your code cross-browser compatible for the full set of features.
Dec 3 '10 #10

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

Similar topics

1
12299
by: Antoni | last post by:
Hello, I wondered if anyone could further advice? In my script I was trying allow the user to enter a userid and password, and when the users clicks the login button. Pass these values passed to a method login_user, and finally display there record. I was hoping to display the record on this page. I would appreicate some advice if my scrips looks corrects? I unsure about the line if(isset($_POST)){?
2
1813
by: mohdowais | last post by:
Hi all, I am running an ASP 3.0 application on a Windows 2000 Advanced server. We've recently added new functionality to the application that allows users to click on a link, and view an attached document (opens in a new window). Nearly everybody using Word 2000 has been complaining that they get an "Enter Network Password" dialog box, that prompts for the username and password, while opening only Word and Excel files. RTF, Image and plain...
5
2098
by: Alan Zhong | last post by:
i am trying to similate an "ENTER" as a key to switch focus in a sequence of text inputs. i don't want to use "event.keyCode" since i want to do additional testing before i decide which text input i want to focus next. the following are the test code i have, whenever i hit "enter", it will act clicking the submit button. what can i do to avoid this problem? <!-- ############# code begins here ############ --> <html> <head>
1
7510
by: Matt | last post by:
<input type="button" onClick="doSomething()"> When the user click HTML button, it will launch doSomething(). But I want the user enter ENTER key, it will have same effect. Please advise. Thanks!
1
2066
by: Empire City | last post by:
Enter network password appears when I open a VS Web application and again when I start it before the aspx page appears. IIS is installed on my C: drive but the above project/site is pointing the site to a folder on my E: drive. When I have a project on the C: drive it does not ask for the network password. I've installed the Duwamish sample to my E: drive and that does not prompt for all the passwords. I've added all the users involved...
1
1650
by: Laszlo Henning | last post by:
I would like to make it possible to jump from a field to another field (the next one in the tab index) using enter also and not only tab. How can this be done either without onkeydown or with it. Laszlo Henning
1
2953
by: Ezra | last post by:
Our company's web server is trying to access graphics files on another server. When I run the app from Visual Studio (1.0) on my localhost, the server in question is available (which is accessed a virtual directory) and I'm able to display the files. However, when we logon to the intranet through a browser, and click the link which will display the files, we get the "Enter Network Password" logon box. We set the proper permissions on...
3
2379
by: David Lozzi | last post by:
Howdy, I'm using asp.net 2.0 and am trying to get one text box on the page, after the user presses enter, to "click" a specific button. I copied the javascript I used for a .net 1.1 web app I did a while ago but it doesn't appear to work with .net 2.0? Below is my script. Any ideas? <script language="javascript"> function clickButton(e, buttonid){
1
2995
by: BisterBooster | last post by:
Hi, Can someone help me for next problem How to for using ENTER key to move to the right cell instead of the TAB key Many thanks in advance Marc.
1
1639
by: Mahesh J K | last post by:
Hi, Pls help me in solving this problem. How to trigger radio button element's eventhandler from the mail body of the mail I am trying like this... strHTMLBody = "<html><head><script language='javascript'>function fdBckMail(){alert('HI')}</script></head><body><CENTER><SPAN style='FONT-SIZE: 10.5pt; COLOR: #0000ff; FONT-FAMILY: Bookman Old Style'>***********THIS IS AN AUTOGENERATED MAIL***********</span><BR><BR></CENTER><SPAN...
0
7924
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
8219
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...
1
7978
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8221
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
6629
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...
0
3845
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...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.