Login page cursor not pointing to login box, how can I do that? | Member | | Join Date: Oct 2009
Posts: 126
| |
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. -
<script language="javascript">
-
<!--//
-
/*This Script allows people to enter by using a form that asks for a
-
UserID and Password*/
-
function pasuser(form) {
-
if (form.id.value=="admin") {
-
if (form.pass.value=="admin") {
-
location="control.htm"
-
} else {
-
alert("Invalid Password")
-
}
-
} else if (form.id.value=="user") {
-
if (form.pass.value=="user") {
-
location="status.htm"
-
} else {
-
alert("Invalid Password")
-
}
-
}
-
-
else { alert("Invalid UserID")
-
}
-
}
-
//-->
-
</script>
-
-
<html>
-
-
<head>
-
<title>LOGIN PAGE</title>
-
</head>
-
-
<body>
-
-
<br>
-
<div id="hedeer">
-
</div>
-
-
<center>
-
<table bgcolor="white" cellpadding="12" border="1">
-
<tr><td colspan="2"><center><h1><i><b>Login
-
Area</b></i></h1></center></td></tr>
-
<tr><td><h1><i><b>UserID:</b></i></h1></td><td><form name="login"><input
-
name="id" type="text"></td></tr>
-
<tr><td><h1><i><b>Password:</b></i></h1></td><td><input name="pass"
-
type="password"></td></tr>
-
<tr><td><center><input type="button" value="Login"
-
onClick="pasuser(this.form)"></center></td><td><center><br><input
-
type="Reset"></form></td></tr></table></center>
-
-
-
<br>
-
<br>
-
<br>
-
<tr> <CENTER>
-
<td align="center" width="100%" colspan="2">
-
-
<img border="0" src="footer.gif" width="800" height="25"></td> </CENTER>
-
</tr>
-
-
</body>
-
</html>
-
| |
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: - function setFocus( yourInputNodeId ) {
-
var n = document.getElementById( yourInputNodeId );
-
n.focus();
-
}
-
and the call should look like: - <body onload="setFocus( 'theNodeId_youHaveAdded' );">
kind regards
|  | Moderator | | Join Date: May 2007 Location: Munich, Germany
Posts: 4,136
| | | 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: - function setFocus( yourInputNodeId ) {
-
var n = document.getElementById( yourInputNodeId );
-
n.focus();
-
}
-
and the call should look like: - <body onload="setFocus( 'theNodeId_youHaveAdded' );">
kind regards
| | Member | | Join Date: Oct 2009
Posts: 126
| | | 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
| | | 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.
|  | Moderator | | Join Date: May 2007 Location: Munich, Germany
Posts: 4,136
| | | 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
| | | 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. - <script language="javascript">
-
<!--//
-
/*This Script allows people to enter by using a form that asks for a
-
UserID and Password*/
-
function pasuser(form) {
-
if (form.id.value=="admin") {
-
if (form.pass.value=="admin") {
-
location="control.htm"
-
} else {
-
alert("Invalid Password")
-
}
-
} else if (form.id.value=="user") {
-
if (form.pass.value=="user") {
-
location="status.htm"
-
} else {
-
alert("Invalid Password")
-
}
-
}
-
else { alert("Invalid UserID")
-
}
-
}
-
//-->
-
-
function setFocus(NodeId) {
-
-
var n = document.getElementById(NodeId);
-
n.focus();
-
}
-
</script>
-
-
<html>
-
-
<head>
-
<title>LOGIN PAGE</title>
-
</head>
-
-
<body onload="setFocus('UserID');">
-
-
<body>
-
-
<br>
-
<div id="header">
-
</div>
-
-
<center>
-
<table bgcolor="white" cellpadding="12" border="1">
-
<tr><td colspan="2"><center><h1><i><b>Login
-
Area</b></i></h1></center></td></tr>
-
<tr><td><h1><i><b>UserID:</b></i></h1></td><td><form name="login"><input
-
name="id" type="text"></td></tr>
-
<tr><td><h1><i><b>Password:</b></i></h1></td><td><input name="pass"
-
type="password"></td></tr>
-
<tr><td><center><input type="button" value="Login"
-
onClick="pasuser(this.form)"></center></td><td><center><br><input
-
type="Reset"></form></td></tr></table></center>
-
-
-
<br>
-
<br>
-
<br>
-
<tr> <CENTER>
-
<td align="center" width="100%" colspan="2">
-
-
<img border="0" src="footer.gif" width="800" height="25"></td> </CENTER>
-
</tr>
-
-
</body>
-
</html>
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,669
| | | 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
| | | 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)").
|  | Moderator | | Join Date: May 2007 Location: Munich, Germany
Posts: 4,136
| | | re: Login page cursor not pointing to login box, how can I do that?
as far as i could see ... this: - <input name="id" type="text">
-
should be that: - <input name="whatever" id="UserID" type="text"/>
kind regards
| | Member | | Join Date: Oct 2009
Posts: 126
| | | 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?.
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,669
| | | re: Login page cursor not pointing to login box, how can I do that? Quote:
Originally Posted by tvnaidu 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
| | | 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?.
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,669
| | | 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
| | | 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
| | | 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: - <input name="whatever" id="UserID" type="text"/>
previous: - <input name="id" type="text">
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,669
| | | re: Login page cursor not pointing to login box, how can I do that? Quote:
Originally Posted by tvnaidu Is there anyway password display can scramble in view source?. nope.
that’s why password validation usually is made server side.
|  | Moderator | | Join Date: May 2007 Location: Munich, Germany
Posts: 4,136
| | | 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
| | | 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. - <input name="whatever" id="UserID" type="text"/>
|  | Moderator | | Join Date: May 2007 Location: Munich, Germany
Posts: 4,136
| | | 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: - <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
| | | 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.
|  | Moderator | | Join Date: May 2007 Location: Munich, Germany
Posts: 4,136
| | | 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
| | | 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.
|  | | | | Forums
Visit our community forums for general discussions and latest on Bytes
/bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,567 network members.
|