Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Member
 
Join Date: Oct 2009
Posts: 126
#1: Oct 22 '09
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.  
best answer - posted 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

gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,136
#2: Oct 22 '09

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


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
Member
 
Join Date: Oct 2009
Posts: 126
#3: Oct 22 '09

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


Thanks you verymuch, appreciated.
Member
 
Join Date: Oct 2009
Posts: 126
#4: Oct 22 '09

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


I added the function part of javascript, then I added function call in body, but still I cannot see cursor.
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,136
#5: Oct 22 '09

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


did you add the id too? ... show the code you are using ... so that we might see what the problem could be.

kind regards
Member
 
Join Date: Oct 2009
Posts: 126
#6: Oct 22 '09

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


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>
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,669
#7: Oct 22 '09

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


did you really use that? it should be giving an error (<script> tags are supposed to be in the <head>/<body> not outside <html>)
Member
 
Join Date: Oct 2009
Posts: 126
#8: Oct 22 '09

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


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)").
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,136
#9: Oct 22 '09

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


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
Member
 
Join Date: Oct 2009
Posts: 126
#10: Oct 22 '09

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


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?.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,669
#11: Oct 22 '09

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


Quote:

Originally Posted by tvnaidu View Post

YBut when I view "page source", I can see complete javascript, also it shows both passwords for admin and user

that’s the problem with passwords in Javascript, you cannot hide them.
Member
 
Join Date: Oct 2009
Posts: 126
#12: Oct 22 '09

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


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?.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,669
#13: Oct 22 '09

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


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…)
Member
 
Join Date: Oct 2009
Posts: 126
#14: Oct 22 '09

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


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
Member
 
Join Date: Oct 2009
Posts: 126
#15: Oct 22 '09

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


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">
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,669
#16: Oct 22 '09

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


Quote:

Originally Posted by tvnaidu View Post

Is there anyway password display can scramble in view source?.

nope.

that’s why password validation usually is made server side.
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,136
#17: Oct 22 '09

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


your check relies on an input named 'id' ... so you shouldn't have changed the name of the input-node ... rechange it to 'id' ...
Member
 
Join Date: Oct 2009
Posts: 126
#18: Oct 23 '09

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


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"/>
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,136
#19: Oct 23 '09

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


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.
Member
 
Join Date: Oct 2009
Posts: 126
#20: Oct 23 '09

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


Thank you for your help, appreciated, I got it now. It is my mistake.
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,136
#21: Oct 24 '09

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


no problem :) ... just post back to the forum in case you have more questions

kind regards
Member
 
Join Date: Oct 2009
Posts: 126
#22: Oct 24 '09

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


Gits.

Actually I posted another one, it prints half-way, remaining half not printing.
Reply