Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set Focus on input area

Status
Not open for further replies.

bevan

Programmer
Jan 11, 2001
22
0
0
GB
HI,
I have code to set focus on an input area (type="text") or even to select the default text value...... BUt when it does automatically select the text value I can't write to it. I have to tab out of the field and then back in again to be able to write to it?
Why does it select the text, but not let me change it?

Here is part of my code....

THE TABLE


<tr>
<td width=&quot;25%&quot; height=&quot;21&quot;></td>
<td width=&quot;25%&quot; height=&quot;21&quot;>New Projected Budget:</td>
<td width=&quot;25%&quot; height=&quot;21&quot;><input type=&quot;text&quot; name=&quot;NewBudget&quot; tabindex=&quot;1&quot; size=&quot;20&quot; value=&quot;0&quot;></td>
<td width=&quot;25%&quot; height=&quot;21&quot;></td>
</tr>
</TABLE>
</FORM>


AND THE END OF THE PAGE WHICH HAS THE SCRIPT


<SCRIPT language=JavaScript>document.frmBudget.NewBudget.select();</SCRIPT>
</BODY>
</HTML>



I have also tried .focus instead of .select or both together.

Any comments?
 
hi,you can call the object itself.
Example:

Assuming you have the text box named text1.

<INPUT id=text1 name=text1>

Assuming you have a button that when you click, you pass the focus to the text1, text box.

<INPUT id=button1 name=button1 type=button value=Button onclick=&quot;text1.focus();&quot;>

this will set the focus in the text box.

Best Regard's
Vegeta
(please vote for me)
 
Thanks guys but your ideas didn't actually help.
The code WILL select the text, but it won't let you write over it? Then you go to another area, go back again and NOW you can change the text.
I want the user to just be able to put in the value as soon as they enter the screen. SO at the moment it seems as though the code works, but only half works?


Bevan
 
Change the javascript at the bottom of the page to this:
<script language=JavaScript>document.frmBudget.NewBudget.select();document.frmBudget.NewBudget.focus();</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top