/    Sign up×
Community /Pin to ProfileBookmark

Default Focus

default focus

In my webpage there is a table of text boxes. I would like the focus to be set on a particular text box when the page opens or refreshes.

Many Thanks.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@KorNov 06.2006 — try:
<i>
</i>&lt;script type="text/javascript"&gt;
onload=function(){
document.forms['formname'].elements['elementname'].focus();
}
&lt;/script&gt;
Copy linkTweet thisAlerts:
@AK74authorNov 08.2006 — Sorry Kor, the code didn't quite work.

Code is as follows:

<?xml version="1.0" ?>

<html>

<head>

<title>TPHEADER</title>

<link REL="stylesheet" HREF="eform.css" TYPE="text/css" />

<meta name="GENERATOR" content="Microsoft FrontPage 3.0" />

<script Language="JavaScript" src="eform.js"></script>

<script Language="Javascript">

var mbStopSectionSet;



function setDefaultSection(){

document.forms['fmHdr'].Elements['edtSrcTpName'].focus();



} ;



</script>

<base target="contents" />

</head>

<body bgcolor="#C0C0C0" onLoad="setDefaultSection()">

<form name="fmHdr">


<table border="0" name="goupData" cellspacing="0" cellpadding="0" width="100%">

<tr>

</tr>
<tr>
<td width="24%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="50%">Sender</td>
<td width="50%"><input TYPE="text" ID="edtSrcTpName"
Language="VBScript" size="20" fieldname="SrcTpName" transName="edtDestTpName"></td>
</tr>

<tr>
<td width="50%">Reference</td>
<td width="50%"><input TYPE="text" NAME="edtSrcReference" size="20" fieldname="SrcRef" transName="edtDestReference"></td>
</tr>

</table>
</td>
<td width="12%"></td>
<td width="25%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="50%">Recipient </td>
<td width="50%"><input TYPE="text" NAME="edtDestTpName" size="20" fieldname="DestTpName" transName="edtSrcTpName"></td>
</tr>

<tr>
<td width="50%">Reference</td>
<td width="50%"><input TYPE="text" NAME="edtDestReference" size="20" fieldname="DestRef" transName="edtSrcReference"></td>
</tr>

</table>
</td>
<td width="13%"></td>
<td width="26%" valign="top" align="left">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="50%">Important </td>
<td width="50%" align="left"><input type="checkbox" id="chkImportance" fieldName="Importance" ></td>
</tr>
<tr>
<td width="50%">Reply By</td>
<td width="50%"><input TYPE="text" NAME="edtReplyBy" size="10" fieldname="ReplyBy" /></td>
</tr>
</table>
</td>
</tr>

</table>

</form>

</body>

</html>
Copy linkTweet thisAlerts:
@scragarNov 08.2006 — I'm surprised anything works, it's missing a doctype, uses the depreciated language attribute to your script tags and your even missing a charset. Make a note to the fact that I haven't edited your HTML, simply made it more readable. If I get time I may look into it further and see if I can't some up with a fix.[code=html]<?xml version="1.0" ?>
<html>

<head>
<title>TPHEADER</title>
<link REL="stylesheet" HREF="eform.css" TYPE="text/css" />
<meta name="GENERATOR" content="Microsoft FrontPage 3.0" />
<script Language="JavaScript" src="eform.js"></script>
<script Language="Javascript">
var mbStopSectionSet;



function setDefaultSection(){

document.forms['fmHdr'].Elements['edtSrcTpName'].focus();



} ;


</script>

<base target="contents" />
</head>

<body bgcolor="#C0C0C0" onLoad="setDefaultSection()">

<form name="fmHdr">


<table border="0" name="goupData" cellspacing="0" cellpadding="0" width="100%">
<tr>

</tr>
<tr>
<td width="24%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="50%">Sender</td>
<td width="50%"><input TYPE="text" ID="edtSrcTpName"
Language="VBScript" size="20" fieldname="SrcTpName" transName="edtDestTpName"></td>
</tr>

<tr>
<td width="50%">Reference</td>
<td width="50%"><input TYPE="text" NAME="edtSrcReference" size="20" fieldname="SrcRef" transName="edtDestReference"></td>
</tr>

</table>
</td>
<td width="12%"></td>
<td width="25%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="50%">Recipient </td>
<td width="50%"><input TYPE="text" NAME="edtDestTpName" size="20" fieldname="DestTpName" transName="edtSrcTpName"></td>
</tr>

<tr>
<td width="50%">Reference</td>
<td width="50%"><input TYPE="text" NAME="edtDestReference" size="20" fieldname="DestRef" transName="edtSrcReference"></td>
</tr>

</table>
</td>
<td width="13%"></td>
<td width="26%" valign="top" align="left">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="50%">Important </td>
<td width="50%" align="left"><input type="checkbox" id="chkImportance" fieldName="Importance" ></td>
</tr>
<tr>
<td width="50%">Reply By</td>
<td width="50%"><input TYPE="text" NAME="edtReplyBy" size="10" fieldname="ReplyBy" /></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>[/code]
×

Success!

Help @AK74 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...