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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting focus on buttons, need help

Status
Not open for further replies.

taval

Programmer
Jul 19, 2000
192
GB
I currently have a page with several text boxes with respective buttons i.e.<br><br>&lt;text box1&gt;&lt;button1&gt;<br>&lt;text box2&gt;&lt;button2&gt;<br>&lt;text box3&gt;&lt;button3&gt;<br><br>how do I implement code so that if the text box has the focus i.e. I have clicked on the text box or entered data in that box that the focus goes on the respective button. So that when the return key is pressed the button next to the text box is pressed.<br><br>my code currently looks something like this:<br><br>-------------------------------------------------<br><br>&lt;FORM METHOD=&quot;POST&quot;&nbsp;&nbsp;NAME=&quot;login&quot;&nbsp;&nbsp;ACTION=&quot;webdb.asp&quot;&nbsp;&nbsp;onSubmit=&quot;return checkPass()&quot;&gt;<br>&lt;center&gt;&lt;font face=&quot;Arial,Helvetica&quot;&gt;&lt;font size=+2&gt;BackPocket Database&lt;/font&gt;&lt;/font&gt;&lt;/center&gt;<br><br>&lt;center&gt;<br>&lt;TABLE width=600&gt;<br><br>&lt;TR&gt;<br>&lt;TD BGCOLOR=#FFFFCC&gt;<br>List all customers with BackPocket service<br>&lt;/TD&gt;<br>&lt;TD BGCOLOR=#99FF99 align= center&gt;<br>&lt;input name=&quot;Customers&quot; type=&quot;submit&quot; value=&quot;List Customers&quot; onclick=&quot;javascript:gotonectpage(this);&quot;&gt;<br>&lt;/TD&gt;<br>&lt;/TR&gt;<br><br>&lt;TR&gt;<br>&lt;TD BGCOLOR=#FFFFCC &gt; Search query on<br>&lt;select NAME=&quot;CustQuery&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;option VALUE=&quot;CustID&quot;&gt;Customer ID<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;option VALUE=&quot;CustName&quot;&gt;Customer Name<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;option VALUE=&quot;CustEmail&quot;&gt;Customer E-mail<br>&lt;/select&gt; with value of<br>&nbsp;<br><br>&lt;INPUT TYPE=&quot;text&quot;&nbsp;&nbsp;NAME=&quot;SQLvariable&quot; size=16&gt;<br>&lt;/TD&gt;<br>&lt;TD BGCOLOR=#99FF99 align= center&gt;<br>&lt;input name=&quot;button&quot; type=&quot;submit&quot; value=&quot;Search&quot; onclick=&quot;javascript:gotonectpage(this);&quot;&gt;<br>&lt;/TD&gt;<br>&lt;/TR&gt;<br><br>&lt;TD BGCOLOR=#FFFFCC&gt;Search for customers who have not backed-up in &nbsp;&lt;INPUT TYPE=&quot;text&quot;&nbsp;&nbsp;NAME=&quot;days&quot; size=6 maxlength=6&gt;<br>days<br>&lt;/TD&gt; <br>&lt;TD BGCOLOR=#99FF99 align= center &gt;<br>&lt;INPUT name=&quot;Customers&quot; TYPE=&quot;submit&quot;&nbsp;&nbsp;VALUE=&quot;Backed Up&quot; onclick=&quot;javascript:gotonectpage(this);&quot;&gt;<br>&lt;/TD&gt;<br>&lt;/TR&gt;<br><br>&lt;br&gt;<br>&lt;/TD&gt;<br>&lt;/TR&gt;<br>&lt;/TABLE&gt;<br>&lt;/center&gt;<br>&lt;/FORM&gt;<br>&lt;/CENTER&gt;<br>&lt;/BODY&gt;<br>&lt;/HTML&gt;<br><br>-------------------------------------------------<br><br>grateful for any help given.<br><br>
 
there might also be another way around this in that after you type in the box and press the return key, it automtically presses the respective button. I was wondering how would I also do this?
 
I've tried looking around the Internet to find out how to do this, if anyone knows the solution to the problem above I would be grateful if you could help me out?<br>Thankx
 
Seems to me this should work:<br><br>document.login.days.onfocus = function() {<br><br>&nbsp;&nbsp;document.login.daysButton.focus()<br><br>}<br><br>This adds focus to the proper button when the corresponding text box is focused (clicked within).<br><br>BTW you have to name each of your buttons; I named your button &quot;daysButton&quot; in the above example.&nbsp;&nbsp;You need to make a statement like this for each box and button, and call the whole set with the BODY's onload handler.&nbsp;&nbsp;Get it?<br><br> <p>scottandrew<br><a href=mailto:scott@scottandrew.com>scott@scottandrew.com</a><br><a href= / Scripting / CGI
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top