Asp set focus on text box

Posted on 2012-09-06
Last Modified: 2012-09-06
I have this code: -
<meta name="GENERATOR" content="Microsoft Developer Studio"/>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<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>

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!
Question by:HKFuey
    LVL 52

    Expert Comment

    by:Scott Fell, EE MVE
    Ok get rid of the body onload and place this script below your form.

    <script type="text/javascript" language="JavaScript">

    Since submitting is the same as refreshing your page, this will work either way.
    LVL 52

    Accepted Solution

    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">
    if request.form("x") = "yes" then
        response.write  "document.forms['Serial'].elements['Dnote'].focus();"
    end if

    Author Closing Comment

    Thanks padas your first suggestion works great and thanks for the extra info!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Do you want to insert HTML5 video into your site? This is the tutorial how to do so. What are the main advantages of HTML5 video? 1) Have good compression, good image quality, and low decode processor use. 2) It is royalty-free 3) It is easi…
    Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
    In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
    In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now