Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 662
  • Last Modified:

Asp set focus on text box

I have this code: -
<html>
<head>
<meta name="GENERATOR" content="Microsoft Developer Studio"/>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>Serials</title>
</head>
<body onload="setFocus('Dnote')" bgcolor="#CEE3F6" text="#000000">
<form name="Serial" action="Serials.asp" method="post">            
<table width="60%" border="0" align="left">  		
<tr><td width="10%"></td><td><input name="Add" type="submit" value="Update" onclick="setFocus('Dnote')"/></td></tr>
<tr><td width="50%"></td></tr>
	<tr><td width="10%"></td><td width="50%">Scan Dispatch Note Number</td></tr>
	<tr><td width="10%"></td><td><input name="Dnote" type="text" maxlength="30"  size="30"/></td></tr>
	<tr><td width="10%"></td><td width="50%">Scan Serial</td></tr>
    <tr><td width="10%"></td><td><input type="text" name="Serial" id="Serial" size="30"/></td></tr>
	<tr><td width="10%"></td><td width="50%"><%=iMsg%></td></tr>
</table>
</form>
</body>
</html>

Open in new window


On opening the page or pressing update I want the focus on 'Dnote'

Does anyone know how to do this?
Ps. KIS I'm new at this!
0
HKFuey
Asked:
HKFuey
  • 2
1 Solution
 
Scott Fell, EE MVEDeveloperCommented:
Ok get rid of the body onload and place this script below your form.

<script type="text/javascript" language="JavaScript">
document.forms['Serial'].elements['Dnote'].focus();
</script>

Since submitting is the same as refreshing your page, this will work either way.
0
 
Scott Fell, EE MVEDeveloperCommented:
If you want to control it via your asp, you can do the following where the js will not fire unless the parameter is met.  If it is met, you can view the source of your rendered page and see the js just as if you hard coded it.

<script type="text/javascript" language="JavaScript">
<%
x=request.form("x")
if request.form("x") = "yes" then
    response.write  "document.forms['Serial'].elements['Dnote'].focus();"
end if
%>
</script>
0
 
HKFueyAuthor Commented:
Thanks padas your first suggestion works great and thanks for the extra info!!
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now