473,386 Members | 1,610 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,386 software developers and data experts.

Login page cursor not pointing to login box, how can I do that?

365 100+
This is the Java script I am using fo rlogin page, but cursor not pointing to login box, any idea how can I point cursor to login box when this page loaded?. here admin login take to control page and user login take to status page, if I give direct path without goto login, both pages display, can I add a check if user didn't login, then redirect to login page for both control.htm and status.htm, let me know. thanks in advance.



Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. <!--//
  3. /*This Script allows people to enter by using a form that asks for a
  4. UserID and Password*/
  5. function pasuser(form) {
  6. if (form.id.value=="admin") { 
  7. if (form.pass.value=="admin") {              
  8. location="control.htm" 
  9. } else {
  10. alert("Invalid Password")
  11. }
  12. } else if (form.id.value=="user") {
  13. if (form.pass.value=="user") {
  14. location="status.htm" 
  15. } else {
  16. alert("Invalid Password")
  17. }
  18.  
  19. else {  alert("Invalid UserID")
  20. }
  21. }
  22. //-->
  23. </script>
  24.  
  25. <html>
  26.  
  27. <head>
  28. <title>LOGIN PAGE</title>
  29. </head>
  30.  
  31. <body>
  32.  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  
  33.  <br>
  34. <div id="hedeer">
  35. </div> &nbsp;  &nbsp;  &nbsp; 
  36.  
  37. <center>
  38. <table bgcolor="white" cellpadding="12" border="1">
  39. <tr><td colspan="2"><center><h1><i><b>Login
  40. Area</b></i></h1></center></td></tr>
  41. <tr><td><h1><i><b>UserID:</b></i></h1></td><td><form name="login"><input
  42. name="id" type="text"></td></tr>
  43. <tr><td><h1><i><b>Password:</b></i></h1></td><td><input name="pass"
  44. type="password"></td></tr>
  45. <tr><td><center><input type="button" value="Login"
  46. onClick="pasuser(this.form)"></center></td><td><center><br><input
  47. type="Reset"></form></td></tr></table></center> 
  48.  
  49. &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp; 
  50. <br>
  51. <br>
  52. <br>
  53. <tr> <CENTER>
  54.         <td align="center" width="100%" colspan="2">
  55.  
  56.             <img border="0" src="footer.gif" width="800" height="25"></td> </CENTER>
  57.     </tr>
  58.  
  59. </body>
  60. </html>
  61.  
Oct 21 '09 #1

✓ answered by gits

give your input node an id and then call a function in the body's onload that will focus the node:

Expand|Select|Wrap|Line Numbers
  1. function setFocus( yourInputNodeId ) {
  2.     var n = document.getElementById( yourInputNodeId );
  3.     n.focus();
  4. }
  5.  
and the call should look like:

Expand|Select|Wrap|Line Numbers
  1. <body onload="setFocus( 'theNodeId_youHaveAdded' );">
kind regards

21 3810
gits
5,390 Expert Mod 4TB
give your input node an id and then call a function in the body's onload that will focus the node:

Expand|Select|Wrap|Line Numbers
  1. function setFocus( yourInputNodeId ) {
  2.     var n = document.getElementById( yourInputNodeId );
  3.     n.focus();
  4. }
  5.  
and the call should look like:

Expand|Select|Wrap|Line Numbers
  1. <body onload="setFocus( 'theNodeId_youHaveAdded' );">
kind regards
Oct 22 '09 #2
tvnaidu
365 100+
Thanks you verymuch, appreciated.
Oct 22 '09 #3
tvnaidu
365 100+
I added the function part of javascript, then I added function call in body, but still I cannot see cursor.
Oct 22 '09 #4
gits
5,390 Expert Mod 4TB
did you add the id too? ... show the code you are using ... so that we might see what the problem could be.

kind regards
Oct 22 '09 #5
tvnaidu
365 100+
This is the code, I added function in javascript, then I am calling that function form body. Here my id is "UserID", which is the user id box, I need the curosr to be there.



Expand|Select|Wrap|Line Numbers
  1. <script language="javascript"> 
  2. <!--// 
  3. /*This Script allows people to enter by using a form that asks for a 
  4. UserID and Password*/ 
  5. function pasuser(form) { 
  6. if (form.id.value=="admin") {  
  7. if (form.pass.value=="admin") {               
  8. location="control.htm"  
  9. } else { 
  10. alert("Invalid Password") 
  11. } else if (form.id.value=="user") { 
  12. if (form.pass.value=="user") { 
  13. location="status.htm"  
  14. } else { 
  15. alert("Invalid Password") 
  16. }  
  17. else {  alert("Invalid UserID") 
  18. //--> 
  19.  
  20. function setFocus(NodeId) {
  21.  
  22.         var n = document.getElementById(NodeId);
  23.         n.focus();
  24. }
  25. </script> 
  26.  
  27. <html> 
  28.  
  29. <head> 
  30. <title>LOGIN PAGE</title> 
  31. </head> 
  32.  
  33.  <body onload="setFocus('UserID');">
  34.  
  35. <body> 
  36.  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;   
  37.  <br> 
  38. <div id="header"> 
  39. </div> &nbsp;  &nbsp;  &nbsp;  
  40.  
  41. <center> 
  42. <table bgcolor="white" cellpadding="12" border="1"> 
  43. <tr><td colspan="2"><center><h1><i><b>Login 
  44. Area</b></i></h1></center></td></tr> 
  45. <tr><td><h1><i><b>UserID:</b></i></h1></td><td><form name="login"><input 
  46. name="id" type="text"></td></tr> 
  47. <tr><td><h1><i><b>Password:</b></i></h1></td><td><input name="pass" 
  48. type="password"></td></tr> 
  49. <tr><td><center><input type="button" value="Login" 
  50. onClick="pasuser(this.form)"></center></td><td><center><br><input 
  51. type="Reset"></form></td></tr></table></center>  
  52.  
  53. &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  
  54. <br> 
  55. <br> 
  56. <br> 
  57. <tr> <CENTER> 
  58.         <td align="center" width="100%" colspan="2"> 
  59.  
  60.             <img border="0" src="footer.gif" width="800" height="25"></td> </CENTER> 
  61.     </tr> 
  62.  
  63. </body> 
  64. </html>
Oct 22 '09 #6
Dormilich
8,658 Expert Mod 8TB
did you really use that? it should be giving an error (<script> tags are supposed to be in the <head>/<body> not outside <html>)
Oct 22 '09 #7
tvnaidu
365 100+
Yes, I loaded here, no error, the script gets called when user do "onclick" for verification. you can see line 54 (onClick="pasuser(this.form)").
Oct 22 '09 #8
gits
5,390 Expert Mod 4TB
as far as i could see ... this:

Expand|Select|Wrap|Line Numbers
  1. <input name="id" type="text">
  2.  
should be that:

Expand|Select|Wrap|Line Numbers
  1. <input name="whatever" id="UserID" type="text"/>
kind regards
Oct 22 '09 #9
tvnaidu
365 100+
Yahooooo. It works now. cursor goes to login box by default with the above change.

But when I view "page source", I can see complete javascript, also it shows both passwords for admin and user, mainly I want admin knows both, where as user shouldnot know admin password, is there anyway I shouldnot show passwords with "view" source of this login page?.
Oct 22 '09 #10
Dormilich
8,658 Expert Mod 8TB
@tvnaidu
that’s the problem with passwords in Javascript, you cannot hide them.
Oct 22 '09 #11
tvnaidu
365 100+
after I enter password, if I press "enter" button by default it should login automatically, but it is not logging in until I click on "login" button, is there anyway can I force to login when I press enter from keyboard after entering password?.
Oct 22 '09 #12
Dormilich
8,658 Expert Mod 8TB
I’m not aware of all the possibilities (and maybe there is some default setting possible) but you can intercept the enter key press (there’s some event for keyboard actions somewhere…)
Oct 22 '09 #13
tvnaidu
365 100+
Is there anyway password display can scramble in view source?. or any other mechanism I can use not to show passwords in source code, I using this on small microcontroller based product to control and view status, I can store password in some files and do some comare
Oct 22 '09 #14
tvnaidu
365 100+
After I made the change to get cursor like below, curosr points, but my check fails when I click on login, it says "Invalid user id", if I change back, it passs but cursor not pinting.

now:

Expand|Select|Wrap|Line Numbers
  1. <input name="whatever" id="UserID" type="text"/> 
previous:

Expand|Select|Wrap|Line Numbers
  1. <input name="id" type="text">
Oct 22 '09 #15
Dormilich
8,658 Expert Mod 8TB
@tvnaidu
nope.

that’s why password validation usually is made server side.
Oct 22 '09 #16
gits
5,390 Expert Mod 4TB
your check relies on an input named 'id' ... so you shouldn't have changed the name of the input-node ... rechange it to 'id' ...
Oct 22 '09 #17
tvnaidu
365 100+
Appreciated. If I change back like below, as soon as I enter id and password and click on "login", check fails and it says "invalid user id", see this print coems from line 19 in the above 68 line program.

Expand|Select|Wrap|Line Numbers
  1. <input name="whatever" id="UserID" type="text"/>
Oct 23 '09 #18
gits
5,390 Expert Mod 4TB
what did you do? i just said that you would need to rechange the 'name' attribute to:

Expand|Select|Wrap|Line Numbers
  1. <input name="id" id="UserID" type="text"/>
the focus-method uses the id to identify the node while your check-method uses the name. you need to understand the code a bit ... it is not of great help to you when i would just give you copy and paste code ... since that leads to confusion as you see :)

kind regards

PS: btw. please use [code] tags when posting source-code in your posts.
Oct 23 '09 #19
tvnaidu
365 100+
Thank you for your help, appreciated, I got it now. It is my mistake.
Oct 23 '09 #20
gits
5,390 Expert Mod 4TB
no problem :) ... just post back to the forum in case you have more questions

kind regards
Oct 24 '09 #21
tvnaidu
365 100+
Gits.

Actually I posted another one, it prints half-way, remaining half not printing.
Oct 24 '09 #22

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

Similar topics

8
by: Dan | last post by:
When a user clicks on a link in my menu, I want the background color of the link that comes up in the hover to remain on the destination page. My menu looks like this: <div id="adminmenu"> <a...
3
by: Alien | last post by:
I need to display a top-right pointing arrow cursor, the same type that appears when you move your mouse over the line number margin on the left side. It's not part of the Cursors class, anyone...
9
by: buran | last post by:
Dear ASP.NET Programmers, How can I post data to an ASP.NET login page and pass authentication? The login page uses forms authentication, users must supply usernames and password and have to...
2
by: Iggy Evans | last post by:
Hi My app is trying to login to an ASP.NET site that uses Forms authentication. I am trying to do in my app (what was previously posted in a newsgroup) the same that a browser does 3) The browser...
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...
2
by: Sasquatch | last post by:
I'm still having trouble creating a simple login page using the asp:login control. I followed some instructions in a WROX book, "Beginning ASP.NET 2.0," and the instructions are very straight...
0
bartonc
by: bartonc | last post by:
from MySQLdb import * from time import time class DBServer: def __init__(self, master): self.master = master def Login(self, servername, username, password): #,...
0
bartonc
by: bartonc | last post by:
With one small change to the view/control: self.staticText3 = wx.StaticText(id=wxID_DBCONNECTDIALOGSTATICTEXT3, label='ODBC Data Source Name', name='staticText3',...
3
by: Jennifer.Berube | last post by:
okay...so I got this login script and I edited it all and it seems to run fine...IE it listens to the script as far as permissions go when I place a restriction on a page and when you login it...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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.