By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,454 Members | 3,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,454 IT Pros & Developers. It's quick & easy.

How do I make a form field take focus ?

P: n/a
I want to make a form field take focus ideally coded in the form :-

<form method="post" action="index.php?action=newname">
<input type="text" name="name" size="40" value="" />
<input type="submit" name="submit" value="Create" />
</form>

Many thanks in advance,

Aaron
Jan 22 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Aaron Gray said the following on 1/21/2008 10:22 PM:
I want to make a form field take focus ideally coded in the form :-

<form method="post" action="index.php?action=newname">
<input type="text" name="name" size="40" value="" />
<input type="submit" name="submit" value="Create" />
</form>
comp.infosystems.www.authoring.html

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 22 '08 #2

P: n/a
Randy Webb a écrit :
It is easy to prove me wrong though. Post a script that will determine
if an arbitrary form element can be focused or not.

<input type="text" onfocus="this.blur()" name="inputYouCantFocus">
There is too many way allowing us to hide and/or prevent the focus on an
element, let me add a few to the list.

1) the obvious <input type="hidden">

2) <input disabled="disabled">

3) <input style="opacity:0">

4) <input style="position:absolute;clip:rect(0,0,0,0)">

5)
<div style="overflow:hidden;width:0;height:0">
<input>
</div>

6)
<div style="position:absolute;z-index:1;width:300px;height:100px">
<input style="width:100px">
</div>
<div style="position:absolute;z-index:2;width:300px;height:100px;
background-color:red"></div>

7) with this one, the focus can occur only with a mouse. You got a
keyboard only, you are screwed and can't focus it at all. How a script
would be able to determine if the second input is focusable ?
<input>
<input tabindex="-1">

and many many more tricky ways to hide anything we want.
Happy scripting!
:D

--
laurent
Jan 23 '08 #3

P: n/a
Laurent vilday said the following on 1/23/2008 8:29 AM:
Randy Webb a écrit :
>It is easy to prove me wrong though. Post a script that will determine
if an arbitrary form element can be focused or not.

<input type="text" onfocus="this.blur()" name="inputYouCantFocus">

There is too many way allowing us to hide and/or prevent the focus on an
element, let me add a few to the list.
Look through the thread I posted a URL to. It has a lot of examples of
inputs that can't have focus.
1) the obvious <input type="hidden">

2) <input disabled="disabled">

3) <input style="opacity:0">

4) <input style="position:absolute;clip:rect(0,0,0,0)">

5)
<div style="overflow:hidden;width:0;height:0">
<input>
</div>

6)
<div style="position:absolute;z-index:1;width:300px;height:100px">
<input style="width:100px">
</div>
<div style="position:absolute;z-index:2;width:300px;height:100px;
background-color:red"></div>

7) with this one, the focus can occur only with a mouse. You got a
keyboard only, you are screwed and can't focus it at all. How a script
would be able to determine if the second input is focusable ?
<input>
<input tabindex="-1">

and many many more tricky ways to hide anything we want.
style="visibility: none"
style="display: none"

But, just one is all it takes to show that you can't determine it with
script to prove that it is impossible.

I am curious to see his attempt at it. His last one failed miserably.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 23 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.