Print Page | Close Window

Set Focus

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=4940
Printed Date: 30 March 2026 at 1:26pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Set Focus
Posted By: rcalvert
Subject: Set Focus
Date Posted: 11 August 2003 at 5:32pm

Can anybody tell me how to make the cursor go straight to the first form field without having to click it like on google.

many thanks in advance




Replies:
Posted By: Mikael
Date Posted: 12 August 2003 at 1:41am

If you have a form named "frmSubmit" and a textfeild named "txtFullName" then you just make a javascript that loads on startup:

Put this function in the <head> tag:

function giveFocus() {
document.frmSubmit.txtFullName.focus();
}

Put this in the bodytag:

<body onload="javascript:giveFocus();">

This will do it...



Posted By: MorningZ
Date Posted: 12 August 2003 at 8:47am

can be even more generic than that

function giveFocus() {
    document.forms[0][0].focus();
}

will give focus to the first form's first field (as long as its a field type that accepts focus of course)



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: zMaestro
Date Posted: 12 August 2003 at 3:41pm

or u can just add this code after the filed:

<Script>document.yourform.yourfield.focus()</Script>



Posted By: rcalvert
Date Posted: 12 August 2003 at 4:14pm

Thanks everyone i don't know why i didn't just ask beforethe scripts work great thanks




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net