468,133 Members | 1,475 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,133 developers. It's quick & easy.

Set focus on hypertext link?

I am trying to create a hypertext link (text within an anchor) so that
if the onlly thing the user does is to press Enter, the link will take
affect and navigate properly. The link is not the first "object" on
the page. Tabbing to the hypertext certainly works.

Any ideas?

Rich Blackburn
Feb 10 '06 #1
5 16247
Rich Blackburn wrote:
I am trying to create a hypertext link (text within an anchor) so that
if the onlly thing the user does is to press Enter, the link will take
affect and navigate properly. The link is not the first "object" on
the page. Tabbing to the hypertext certainly works.

Any ideas?


No, you have been too unspecific. Please elaborate.
PointedEars
Feb 10 '06 #2
My apologies. Here is the Reader's Digest version similar to the code
I would LIKE to invoke. I know it is incorrect, but I am looking for
an alternative method to set the focus to the link so if the user
simply presses Enter, the link would be invoked.

<html>
<head>
<title>Menu</title>
</head>
<body onLoad=document.frm.LINK.focus()>
<Form name="frm">
<input type="text" size="6" maxlength="6" name="USER" value="123456">
<A name="LINK" HREF="javascript:sbmt('Mail')"">Email</A>
<form>
</body>
</html>
On Fri, 10 Feb 2006 21:43:34 +0100, Thomas 'PointedEars' Lahn
<Po*********@web.de> wrote:
Rich Blackburn wrote:
I am trying to create a hypertext link (text within an anchor) so that
if the onlly thing the user does is to press Enter, the link will take
affect and navigate properly. The link is not the first "object" on
the page. Tabbing to the hypertext certainly works.

Any ideas?


No, you have been too unspecific. Please elaborate.
PointedEars


Feb 10 '06 #3
Rich Blackburn wrote:
[...] I am looking for an alternative method to set the focus to the
link so if the user simply presses Enter, the link would be invoked.
[...]
<html>
The DOCTYPE declaration is missing before.
<head>
<title>Menu</title>
Be sure to serve the Content-Type header with the `charset' label
if you omit the charset declaration per `meta' element --

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

-- here.
</head>
<body onLoad=document.frm.LINK.focus()> ^^^^^^^^^^^^^^^^^^^^^^^^^
Attribute values containing the `(' or `)' character must be delimited
with single or double quotes. Because of the several exceptions (see
the HTML 4.01 Specification), attribute values should be quoted always.

Hyperlinks are not form controls. Even if they were, it should be the
almost standards-compliant

document.forms['frm'].elements['LINK'].focus().

Correct is here:

<body onload="document.links['LINK'].focus();">

However, I question you forcing the focus when the document is loaded,
patronizing your users.
<Form name="frm">
The `action' attribute value is missing.
<input type="text" size="6" maxlength="6" name="USER" value="123456">
`type="text"' is the default and can be safely omitted here.
<A name="LINK" HREF="javascript:sbmt('Mail')"">Email</A>
Should be at least

<head>
...
<meta http-equiv="Content-Script-Type" content="text/javascript">
...
</head>

<body>
...
<a href="noscript.html" name="LINK"
onclick="sbmt('Mail'); return false;"E-mail</a> ...
</body>

See <URL:http://jibbering.com/faq/#FAQ4_24>
[...]
First write Valid HTML, then use client-side scripting.

<URL:http://validator.w3.org/>
[top post]


Don't. <URL:http://jibbering.com/faq/faq_notes/pots1.html#ps1Post>
HTH

PointedEars
Feb 10 '06 #4
Thomas, that certainly was a most appreciated, thorough, educational
response. I am grateful. I used the validator you so kindly noted
and ended up with the following:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Menu</title>
<meta http-equiv="Content-Script-Type" content="text/javascript"/>
</head>
<body onload="document.links['LINK'].focus();" >
<form name="frm" action="do_nothing" />
<p><input type="text" size="6" maxlength="6" name="USER"
value="123456"/></p>
<p><a href="noscript.html" name="LINK" onclick="sbmt('Mail'); return
false;" >E-mail</a></p>
</form>
</body>
</html>

However, I get an error:

Line: 7
Error: 'document.links.LINK' is null or not an object.

Am I out of airspeed, altitude, and ideas?

Thanks,
Rich Blackburn



On Sat, 11 Feb 2006 00:42:32 +0100, Thomas 'PointedEars' Lahn
<Po*********@web.de> wrote:
Rich Blackburn wrote:
[...] I am looking for an alternative method to set the focus to the
link so if the user simply presses Enter, the link would be invoked.
[...]
<html>


The DOCTYPE declaration is missing before.
<head>
<title>Menu</title>


Be sure to serve the Content-Type header with the `charset' label
if you omit the charset declaration per `meta' element --

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

-- here.
</head>
<body onLoad=document.frm.LINK.focus()>

^^^^^^^^^^^^^^^^^^^^^^^^^
Attribute values containing the `(' or `)' character must be delimited
with single or double quotes. Because of the several exceptions (see
the HTML 4.01 Specification), attribute values should be quoted always.

Hyperlinks are not form controls. Even if they were, it should be the
almost standards-compliant

document.forms['frm'].elements['LINK'].focus().

Correct is here:

<body onload="document.links['LINK'].focus();">

However, I question you forcing the focus when the document is loaded,
patronizing your users.
<Form name="frm">


The `action' attribute value is missing.
<input type="text" size="6" maxlength="6" name="USER" value="123456">


`type="text"' is the default and can be safely omitted here.
<A name="LINK" HREF="javascript:sbmt('Mail')"">Email</A>


Should be at least

<head>
...
<meta http-equiv="Content-Script-Type" content="text/javascript">
...
</head>

<body>
...
<a href="noscript.html" name="LINK"
onclick="sbmt('Mail'); return false;"
>E-mail</a>

...
</body>

See <URL:http://jibbering.com/faq/#FAQ4_24>
[...]


First write Valid HTML, then use client-side scripting.

<URL:http://validator.w3.org/>
[top post]


Don't. <URL:http://jibbering.com/faq/faq_notes/pots1.html#ps1Post>
HTH

PointedEars


Feb 11 '06 #5
Rich Blackburn wrote:
Thomas, that certainly was a most appreciated, thorough, educational
response. I am grateful.
You are welcome. However I would have appreciated it more if you had
followed _all_ recommendations. See the bottom of this posting for
details.
[...]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Menu</title>
<meta http-equiv="Content-Script-Type" content="text/javascript"/>
</head>
<body onload="document.links['LINK'].focus();" >
<form name="frm" action="do_nothing" /> ^^^^[1] ^^[2]

[1] In XHTML 1.0 _Strict_, the `form' element has no `name' attribute.
[2] The element ends here empty.
<p><input type="text" size="6" maxlength="6" name="USER"
value="123456"/></p>
<p><a href="noscript.html" name="LINK" onclick="sbmt('Mail'); return
false;" >E-mail</a></p>
</form>
</body>
</html>
If I feed this to Firefox's XML parser, I get

| XML Parsing Error: mismatched tag. Expected: </body>.
| [...]
| Line Number 14, Column 3:
|
| </form>
| --^

because of the above.
However, I get an error:
In which browser on which operating system and platform
(navigator.userAgent)? With which media type is this
document resource served?
Line: 7
Error: 'document.links.LINK' is null or not an object.

Am I out of airspeed, altitude, and ideas?
Your markup is still not Valid, and the W3C Markup Validator tells you.
Furthermore, I recommend that you do not use XHTML 1.0 Strict here; HTML
4.01 Strict suffices. And you should not use the p(aragraph) element
where there is no text paragraph; use the div(ision) element in that
case instead.
[top post again]


You have been asked already to quote properly. Your repeated disregarding
of recommended posting guidelines is a sign to your readers that you do not
care about them.
PointedEars
Feb 11 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Acorn Tutors | last post: by
9 posts views Thread by Yann.K | last post: by
1 post views Thread by krishna | last post: by
4 posts views Thread by Stephen Poley | last post: by
4 posts views Thread by John Doe | last post: by
11 posts views Thread by Alex.Svetos | last post: by
12 posts views Thread by ppcguy | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.