Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / HTML / October 2008



Tip: Looking for answers? Try searching our database.

FORM with buttons

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joe - 28 Oct 2008 01:48 GMT
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!
Andy - 28 Oct 2008 10:18 GMT
>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...
[quoted text clipped - 12 lines]
>
> 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
+mrcakey - 28 Oct 2008 10:34 GMT
>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...
[quoted text clipped - 12 lines]
>
> 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
Jukka K. Korpela - 28 Oct 2008 18:37 GMT
> 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.

Signature

Yucca, http://www.cs.tut.fi/~jkorpela/

Neredbojias - 28 Oct 2008 11:03 GMT
> 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
[quoted text clipped - 13 lines]
>
> Thanks!

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

Signature

Neredbojias
http://www.neredbojias.org/
http://www.neredbojias.net/

Jukka K. Korpela - 28 Oct 2008 18:42 GMT
> 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.

Signature

Yucca, http://www.cs.tut.fi/~jkorpela/

richard - 29 Oct 2008 04:42 GMT
>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...
[quoted text clipped - 12 lines]
>
>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.
Joe - 31 Oct 2008 03:42 GMT
> >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...
[quoted text clipped - 18 lines]
> 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
rkrite - 29 Oct 2008 06:17 GMT
> 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...
[quoted text clipped - 12 lines]
>
> 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>
Jukka K. Korpela - 29 Oct 2008 16:54 GMT
> 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").

Signature

Yucca, http://www.cs.tut.fi/~jkorpela/

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.