FORM with buttons

J

Joe

I have been scouring html help sites to figure this out, but so far have
not found it. Either it's too easy or maybe it's not possible...

I have a simple form with three buttons in a horizontal row. Actually
it ONLY has buttons, no text fields. How do I specify the SECOND button
to have focus when the form opens, such that if the user simply presses
'Return', the second button's logic is executed? It seems (unless I'm
missing something) that the first button is always defaulting to focus,
and gets executed if user presses 'Return' (if they don't click
anywhere).

Anyone know how to accomplish this? I'm fairly familiar with form HTML
(I'm using '<INPUT..' tag), so it's probably just an option or attribute
I'm not finding.

Thanks!
 
A

Andy

Joe said:
I have been scouring html help sites to figure this out, but so far have
not found it. Either it's too easy or maybe it's not possible...

I have a simple form with three buttons in a horizontal row. Actually
it ONLY has buttons, no text fields. How do I specify the SECOND button
to have focus when the form opens, such that if the user simply presses
'Return', the second button's logic is executed? It seems (unless I'm
missing something) that the first button is always defaulting to focus,
and gets executed if user presses 'Return' (if they don't click
anywhere).

Anyone know how to accomplish this? I'm fairly familiar with form HTML
(I'm using '<INPUT..' tag), so it's probably just an option or attribute
I'm not finding.

Thanks!

Hi Joe,

This is probably the wrong way to do it but it does work...


<html>
<head>
<title>TEST</title>
</head>
<body onload="document.getElementById('button_2').focus();">

<form>
<input type="button" id="button_1" value="ONE">
<input type="button" id="button_2" value="TWO">
<input type="button" id="button_3" value="THREE">
</form>

</body>
</html>


Hope this helps

Andy
 
M

+mrcakey

Joe said:
I have been scouring html help sites to figure this out, but so far have
not found it. Either it's too easy or maybe it's not possible...

I have a simple form with three buttons in a horizontal row. Actually
it ONLY has buttons, no text fields. How do I specify the SECOND button
to have focus when the form opens, such that if the user simply presses
'Return', the second button's logic is executed? It seems (unless I'm
missing something) that the first button is always defaulting to focus,
and gets executed if user presses 'Return' (if they don't click
anywhere).

Anyone know how to accomplish this? I'm fairly familiar with form HTML
(I'm using '<INPUT..' tag), so it's probably just an option or attribute
I'm not finding.

Thanks!

You'll need to use JavaScript to do that, which will cover the 95%+ of users
that have it turned on.

Specificying a tabindex for the relevant button would also help anyone who
isn't using a mouse, but I don't think it would automatically set focus to
that element.

+mrcakey
www.dreamberry.co.uk
 
N

Neredbojias

I have been scouring html help sites to figure this out, but so far
have not found it. Either it's too easy or maybe it's not
possible...

I have a simple form with three buttons in a horizontal row.
Actually it ONLY has buttons, no text fields. How do I specify the
SECOND button to have focus when the form opens, such that if the
user simply presses 'Return', the second button's logic is executed?
It seems (unless I'm missing something) that the first button is
always defaulting to focus, and gets executed if user presses
'Return' (if they don't click anywhere).

Anyone know how to accomplish this? I'm fairly familiar with form
HTML (I'm using '<INPUT..' tag), so it's probably just an option or
attribute I'm not finding.

Thanks!

Javascript is the traditional method but you could also do the same
thing via diligent use of floats.
 
J

Jukka K. Korpela

+mrcakey said:
You'll need to use JavaScript to do that,
Nope.

which will cover the 95%+
of users that have it turned on.

87.6% of all percentages have just been made up.
 
J

Jukka K. Korpela

Joe said:
I have a simple form with three buttons in a horizontal row.

That's not a simple form. No form with more than one button is simple (in
operation, as regards to defined and actual behavior).
Actually
it ONLY has buttons, no text fields.

Actually it should probably be three links then.

Links want to be links.

If you really have a reason to use buttons, put each button into a form of
its own. You can't? Then what _is_ the problem? URL?
How do I specify the SECOND
button to have focus when the form opens,

You don't, in any reliable way.
such that if the user
simply presses 'Return', the second button's logic is executed?

That's another issue where you don't have a reliable way. (Probably the
focused button is the one activated when you hit Return, but there is no
guarantee.)

And _if_ you could do that, the behavior would be counter-intuitive, since
normally the _first_ button gets used.
IT seems (unless I'm missing something) that the first button is always
defaulting to focus,

The operative word being "seems". It's what browsers probably do these days,
but as it has not been specified, it's gray area.
I'm fairly familiar with form
HTML (I'm using '<INPUT..' tag), so it's probably just an option or
attribute I'm not finding.

It's nothing like that.
 
R

richard

I have been scouring html help sites to figure this out, but so far have
not found it. Either it's too easy or maybe it's not possible...

I have a simple form with three buttons in a horizontal row. Actually
it ONLY has buttons, no text fields. How do I specify the SECOND button
to have focus when the form opens, such that if the user simply presses
'Return', the second button's logic is executed? It seems (unless I'm
missing something) that the first button is always defaulting to focus,
and gets executed if user presses 'Return' (if they don't click
anywhere).

Anyone know how to accomplish this? I'm fairly familiar with form HTML
(I'm using '<INPUT..' tag), so it's probably just an option or attribute
I'm not finding.

Thanks!

Have you considered the possibility of giving focus to the "enter" key
itself?

After all, a button is only an option. If you define what happens when
enter is pressed, then who cares what button has focus.
 
R

rkrite

I have been scouring html help sites to figure this out, but so far have
not found it.  Either it's too easy or maybe it's not possible...

I have a simple form with three buttons in a horizontal row.  Actually
it ONLY has buttons, no text fields.  How do I specify the SECOND button
to have focus when the form opens, such that if the user simply presses
'Return', the second button's logic is executed?  It seems (unless I'm
missing something) that the first button is always defaulting to focus,
and gets executed if user presses 'Return' (if they don't click
anywhere).

Anyone know how to accomplish this?  I'm fairly familiar with form HTML
(I'm using '<INPUT..' tag), so it's probably just an option or attribute
I'm not finding.

Thanks!

I am not sure if this will work exactly, but you may consider the
position of the elements and how this affects behaviour of the form/
page.
Also not sure if the page will get focus initially on the first
element, perhaps it will if all elements are within a <form>....
eg....
<head>
<style type="text/css">
input {position:absolute;}
#one{top:0;}
#two{top:30;}
#three{top:60;}
</style>
</head>

<body>
<input type="button" id="two" value="two">
<input type="button" id="one" value="one">
<input type="button" id="three" value="three">
</body>
 
J

Jukka K. Korpela

rkrite said:
I am not sure if this will work exactly,

How about testing before posting?
but you may consider the
position of the elements and how this affects behaviour of the form/
page.

Why would that matter? It would be very odd if it did.
#three{top:60;}

You didn't bother running even syntax check on your CSS, did you? That way
you generate documents that work very differently on standards-conforming
browsers than on sloppy browsers (including perhaps "quirks mode").
 
J

Joe

richard said:
Have you considered the possibility of giving focus to the "enter" key
itself?

After all, a button is only an option. If you define what happens when
enter is pressed, then who cares what button has focus.


That sounds like it could work for what I want to do. Could you tell me
how you'd do that?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top