By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,316 Members | 2,132 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,316 IT Pros & Developers. It's quick & easy.

set cursor location

idsanjeev
100+
P: 241
how can set cursor location everytime when page is open cursor goes to auto in input field and chake when click on submit lenth of input field
Jan 31 '08 #1
Share this Question
Share on Google+
11 Replies


gits
Expert Mod 5K+
P: 5,333
hi ...

onload of the document you may use:

Expand|Select|Wrap|Line Numbers
  1. var node = document.getElementById('your_node_id');
  2. node.focus();
to set the focus to a specified field (in the example a field with id 'your_node_id'). then later on you may use the form's onsubmit-handler to call a function that should return true or false depending on your check ...

post the code in case you hve problems with that.

kind regards
Jan 31 '08 #2

idsanjeev
100+
P: 241
Hi gits
i have need to chak onclick submit button the lenth of node id help in this
Regard
sanjeev jha
Jan 31 '08 #3

gits
Expert Mod 5K+
P: 5,333
here is a simple example ... adapt it to your needs:

[HTML]<html>
<script type="text/javascript">
function check_form() {
var n = document.getElementById('my_id');
var val = n.value.length > 1;

if (!val) {
alert('more then one char required');
}

n.style.backgroundColor = val ? 'white' : '#FFCC99';

return val;
}
</script>
<body>
<form name="my_form" onsubmit="return check_form();">
<input type="text" id="my_id"/>
<input type="submit" value="Submit"/>
</form>
</body>
</html>
[/HTML]
kind regards
Jan 31 '08 #4

idsanjeev
100+
P: 241
Hi Gits
it works but not focus on my-id
i wants to still on page and cursor focus to my_id but it goes to error after chaking becouse the input field is empty so i wants to still it and don't to any check if my_id field is empty and focus it
Thanks
Regards
Jan 31 '08 #5

gits
Expert Mod 5K+
P: 5,333
please post the code you actually use ...

kind regards
Jan 31 '08 #6

idsanjeev
100+
P: 241
Hi Gits
My code is
Expand|Select|Wrap|Line Numbers
  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <%
  4. Dim conn
  5. Dim R
  6. Dim R1
  7. Dim vempno
  8. Dim emppwd
  9. Dim Veblog
  10. Dim match
  11. Set conn = Server.CreateObject("ADODB.Connection")
  12. conn.Mode = adModeReadWrite
  13. conn.Open "DSN=Oracle; USER ID=gatepass;PASSWORD=gp;"
  14. Set R = Server.CreateObject("ADODB.Recordset")
  15. R.Open "Select a.empno, a.passwd, a.e_blog, b.name, b.empno From emp_authority a, ot_master b where a.empno=b.empno", conn, adOpenStatic, adLockOptimistic, adCmdText
  16. %>
  17. <html>
  18. <head>
  19. <title>Voice Of Baraunians - Login Section</title>
  20. </head>
  21. <!--#include file="front1.inc"-->
  22. <script language="Javascript">
  23. function gofirst()
  24. {
  25.   window.location = "brvoice.asp"
  26.  
  27. }
  28. function chk_val(obj) {
  29.     var chk = /^\d+$/.test(obj.value);
  30.  
  31.     if (!chk) {
  32.         alert('Please Enter Your Employee Number Only');
  33.         obj.focus();
  34.     }
  35. }
  36. function check_form() {
  37.             var n   = document.getElementById('my_id');
  38.             var val = n.value.length =0;
  39.  
  40.             if (!val) {
  41.                 alert('Emplyee no Required for login');
  42.             }
  43.  
  44.             n.style.backgroundColor = val ? 'white' : '#FFCC99';
  45.  
  46.             return val;
  47.         }
  48.  
  49. </script>
  50. <body background="back2.gif">
  51. <form name="myform" onSubmit="return check_form();"  method="POST" action="login.asp">
  52. <div style="Position:Absolute; top:150; left:268">
  53. <center><h2><font face="arial">Welcome To Login Page</font></h2>
  54. </center>
  55. <table border = '0' align = 'center' width = '500' height = '70'>
  56.   <tr>
  57.     <td  align=right>&nbsp;&nbsp;&nbsp;<font face=Arial size=4><b>Employee Number</b></font></td>
  58.     <td >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type= 'text' id="my_id" name="empno" onBlur="chk_val(this)" ></td>
  59.   </tr>
  60.   <tr>
  61.     <td align=right>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font face=Arial size=4 ><b>Password</font></b></td>
  62.     <td >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type= "password" name= "password"></td></font>
  63.   </tr>
  64. </table>
  65. <table style="Position:relative; top:20; left:225"> 
  66. <tr>
  67. </td><td align='center'><input type="submit" name="submit" value="Login" onclick='return checkEntry();'></td>
  68. <td align="right"><input type="button" name="Close" value="Close" onclick="window.close()"></tr>
  69. </table>
  70. </div>
  71. <div style="Position:Absolute; top:265; left:310">
  72. <%
  73. If Not IsEmpty(Request.form("Submit")) Then
  74.   R.MoveFirst
  75.   R.Find "empno = " & Request.Form("empno") & ""
  76.   If Not R.EOF Then
  77.     Match = strComp(R("passwd"), Request.Form("password"))
  78.     If Match = 0 Then
  79.        vempno = Request.Form("empno")
  80.       Response.Cookies("empno") = vempno
  81.       response.Cookies("name")=R("name")
  82.       If R("e_blog")="M" Then
  83.       response.Cookies("e_blog")="M"
  84.       Response.Redirect "moderator1.asp"
  85.       Else
  86.       Response.Redirect "brvoice.asp"
  87.       End If
  88.     Else
  89.       Response.Write "<table><tr><td width=475 align=center><font color=red size= +2><b>Invalid Password</b></font></td></tr></table>"
  90.       End If 
  91.       Else   
  92.       Response.Write "<table><tr><td width=475 align=center><font color=red size=+2><b>Invalid User</b></font></td></tr></table>"  
  93.     End If
  94.  End If
  95. R.Close
  96. Set R = Nothing
  97. conn.Close
  98. Set conn = Nothing
  99. %>
  100. </div>
  101. </form>
  102. </body>
  103. </html>
Jan 31 '08 #7

gits
Expert Mod 5K+
P: 5,333
:) so you want the field focused when there is an error (no employee number was given?) ... so simply add:

Expand|Select|Wrap|Line Numbers
  1. n.focus();
at line 45 to your code ...

kind regards
Jan 31 '08 #8

idsanjeev
100+
P: 241
Hi gits
its focus on that field where i wants but after focus it goes to line 74 where emono is match with database and produce an error there was Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
But some other code when i used the problems whats my need thats solved but i wants to when length of empno is 0 then login goes to false and display a alert massage and other focus in empno


Expand|Select|Wrap|Line Numbers
  1. <script language="Javascript">
  2. function gofirst()
  3. {
  4.   window.location = "brvoice.asp"
  5.  
  6. }
  7. function chk_val(obj) {
  8.     var chk = /^\d+$/.test(obj.value);
  9.  
  10.     if (!chk) {
  11.         alert('Please Enter Your Employee Number Only');
  12.         obj.focus();
  13.     }
  14. }
  15.  
  16.  
  17.         function checkEntry()
  18. {
  19. if (document.getElementById('empno').value.length == 0)return false;
  20. alert('Required Employee no for login');
  21. return true;
  22. }
  23.  
  24. </script>
  25.  
Expand|Select|Wrap|Line Numbers
  1. <body background="back2.gif">
  2. <form name="myform"   method="POST" action="login.asp">
  3. <div style="Position:Absolute; top:150; left:268">
  4. <center><h2><font face="arial">Welcome To Login Page</font></h2>
  5. </center>
  6. <table border = '0' align = 'center' width = '500' height = '70'>
  7.   <tr>
  8.     <td  align=right>&nbsp;&nbsp;&nbsp;<font face=Arial size=4><b>Employee Number</b></font></td>
  9.     <td >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type= 'text' id="my_id" name="empno" onBlur="chk_val(this)" ></td>
  10.   </tr>
  11.   <tr>
  12.     <td align=right>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font face=Arial size=4 ><b>Password</font></b></td>
  13.     <td >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type= "password" name= "password"></td></font>
  14.   </tr>
  15. </table>
  16. <table style="Position:relative; top:20; left:225"> 
  17. <tr>
  18. </td><td align='center'><input type="submit" name="submit" value="Login" onclick='return checkEntry();'></td>
  19. <td align="right"><input type="button" name="Close" value="Close" onclick="window.close()"></tr>
  20. </table>
  21. </div>
  22. <div style="Position:Absolute; top:265; left:310">
  23.  

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%
  3. If Not IsEmpty(Request.form("Submit")) Then
  4.   R.MoveFirst
  5.   R.Find "empno = " & Request.Form("empno") & ""
  6.   If Not R.EOF Then
  7.     Match = strComp(R("passwd"), Request.Form("password"))
  8.     If Match = 0 Then
  9.        vempno = Request.Form("empno")
  10.       Response.Cookies("empno") = vempno
  11.       response.Cookies("name")=R("name")
  12.       If R("e_blog")="M" Then
  13.       response.Cookies("e_blog")="M"
  14.       Response.Redirect "moderator1.asp"
  15.       Else
  16.       Response.Redirect "brvoice.asp"
  17.       End If
  18.     Else
  19.       Response.Write "<table><tr><td width=475 align=center><font color=red size= +2><b>Invalid Password</b></font></td></tr></table>"
  20.       End If 
  21.       Else   
  22.       Response.Write "<table><tr><td width=475 align=center><font color=red size=+2><b>Invalid User</b></font></td></tr></table>"  
  23.     End If
  24.  End If
  25. R.Close
  26. Set R = Nothing
  27. conn.Close
  28. Set conn = Nothing
  29. %>
  30.  
regards
Feb 1 '08 #9

gits
Expert Mod 5K+
P: 5,333
try to adapt the checkEntry()-function, since your if-statement looks weird:

Expand|Select|Wrap|Line Numbers
  1. function checkEntry() {
  2.     var n   = document.getElementById('empno');
  3.     var val = true;
  4.  
  5.     if (n.value.length == 0) {
  6.         alert('Required Employee no for login');
  7.         val = false;
  8.     }
  9.  
  10.     return val;
  11. }
kind regards
Feb 1 '08 #10

idsanjeev
100+
P: 241
Hi Gits
Thanks Now its working according to my need .
Thanks again
Regrads
Feb 1 '08 #11

gits
Expert Mod 5K+
P: 5,333
no problem ... glad you got it working :) ... post back to the forum anytime you have more questions ...

kind regards
Feb 1 '08 #12

Post your reply

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