Solved

Focus question...

Posted on 1998-07-21
18
289 Views
Last Modified: 2010-04-09
What I want to be able to do is have a radio button that once you click on it, it sets the focus to a text area...  I've tried this:

<inut type="radio" .......   ONCLICK="keyword.Focus">

I've also tried the same thing, but specifying the form that keyword is in, i.e. (ONCLICK="CatForm.keyword.Focus").

Well, sometimes this works.  Sometimes it doesn't.  It's almost like the click on the radio button is taking place after the Focus method.  Is there a better way to do this?  Please let me know.  Thanks!

---LSILes
les@livingscriptures.com

p.s.  I would prefer a non-subroutine answer.  =)
0
Comment
Question by:LSILes
  • 7
  • 5
  • 3
  • +3
18 Comments
 
LVL 5

Expert Comment

by:Christian_Wenz
ID: 1844774
just guessing, but have you tried document.elementName.focus() ?
0
 

Author Comment

by:LSILes
ID: 1844775
Just tried it....   didn't work for me.  Thanks for the guess though.
0
 
LVL 2

Expert Comment

by:Quixote
ID: 1844776
if they are in the same form, then you can do it this way:

<inut type="radio" ... onClick="this.form.keyword.focus()">
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:LSILes
ID: 1844777
No Quixote....  I'm afraid you can't...  it gives me the error message of:

Object required...

It does not work.  Please try again though.

---LSILes
les@livingscriptures.com
0
 

Expert Comment

by:speaker
ID: 1844778
Try this:

<INPUT TYPE="RADIO" ... ONCLICK="this.form.TEXTAREA_NAME.focus()">...

Good Luck,
Speaker                  
0
 
LVL 2

Expert Comment

by:Quixote
ID: 1844779
wait a minit... "keyword" is the name of the text area you want to focus, yes?  Isn't speaker saying the same thing you've said doesn't work?  If you haven't made "keyword" the name of the text area, you need to --

<textarea name="keyword">Bring me into focus!</textarea>
0
 

Author Comment

by:LSILes
ID: 1844780
First....  who ever said that it was a textarea?  I didn't.  There are input boxes of type select and text that I want to perform this with.

Also, I have already named my text box.  And what speaker suggested did not work.  It brings up the message Object required...  and yes, I already have my Form named correctly.

Please help me....   thanks!

---LSILes
les@livingscriptures.com
0
 
LVL 2

Expert Comment

by:Quixote
ID: 1844781
could you post a URL or the code?
0
 

Author Comment

by:LSILes
ID: 1844782
Sorry, I forgot to reject your answer last time speaker...  and here is the code:

<form name="CatForm" action="catalog1.asp" method="post">
<input type="radio" name="searchtype" value="category" checked><font size="+1">Select a category that you are interested in</font><br>
<br>
<select name="category" checked ONCHANGE="CatForm.submit">
  <option value="2804,3096,3103,2812,3071,3088">Book of Mormon
  <option value="2934,2942,2950,2423">Dramatized Audio Tape Sets
  <option value="1224,1054,1192">Music Videos
  <option value="1232,1062,1208">Song Books
  <option value="1208">Coloring Books
  <option value="1168,1038">Activity Books
  <option value="2991">Story Books
  <option value="1176,1046,1184">Music Audio Cassettes
  <option value="6060">Music Compact Disc
  <option value="1240,2026,1070,5186,2083,2326">Single Videos
</select><br>

<br>
<font size="+1">OR</font><br>
<br>
<input type="radio" name="searchtype" value="keywords"><font size="+1">Try searching for a product with keywords</font><br>
<br>
<input type="text" name="keywords"><br>
<br>
<font size="+1">OR</font><br>
<br>
<input type="radio" name="searchtype" value="prodno"><font size="+1">If you know the number of the product<br>
                you're looking for, type it here</font><br>
<br>
<input type="text" name="prodno"><br>
<br>
<hr width=75%>
<center><input type="submit" value="Find Item(s)" LANGUAGE="VBScript" ONCLICK="Call CheckValues"><input type="reset" value="Clear Form"></center>
<hr width=75%>
</form>

Hope that helps.  Thanks!

---LSILes
les@livingscriptures.com
0
 
LVL 1

Expert Comment

by:acsmith
ID: 1844783
try onClick="searchtype.focus()"
Depending on the browser, you may wish to specify javascript: onClick="javascript:searchtype.focus()"
also remeber that javascript is case sensitive.
0
 
LVL 2

Expert Comment

by:Quixote
ID: 1844784
methinks acsmith may be mistaken as to which field is to be focused.  Here's my suggestion, based entirely on the assumption that I have a clue as to what you're asking...  :)

<input type="radio" name="searchtype" value="keywords" onClick="this.form.keywords.focus()"><font size="+1">Try searching for a product with keywords</font><br>
<br>
<input type="text" name="keywords"><br>

or

<input type="radio" name="searchtype" value="keywords" onClick="document.CatForm.keywords.focus()"><font size="+1">Try searching for a product with keywords</font><br>
<br>
<input type="text" name="keywords"><br>

and if that doesn't work then I'm gonna go cry in a corner and ask you what browser you're testing on, cuz that works on every browser I've got.  This is starting to reach quest status.
0
 

Author Comment

by:LSILes
ID: 1844785
Okay....  well, that does just about the same thing that I first explained.  Let me try to restate my problem:

I understand that I can use <input type="radio" .....   ONCLICK="keywords.Focus()"> and the like, but what my problem is, is that it only works randomly.  It doesn't work every time.  I'm not sure exactly why, but I think it has something to do with the fact that it's trying to focus on the text box that the radio ONCLICK function points to, but  then it focuses back on the radio button that I'm actually clicking on after the ONCLICK function has taken place.  If that makes sense, and anyone knows what I'm talking about, let me know.  

And please...  if you're going to send me examples, try them yourself to make sure they work first.  Thanks!

---LSILes
les@livingscriptures.com
0
 
LVL 1

Expert Comment

by:acsmith
ID: 1844786
what you said about it focussing back on the radio button makes sense. How about using using the settimeout method to cause a small delay after the radio button has been clicked, and then call the focus method(thus giving the radio buttons own click event time to complete)? Haven't got time to test it right now, but I guess it would go something like onclick="setTimeout('keywords.Focus()',200)" (where 200 is milliseconds)
0
 
LVL 2

Expert Comment

by:Quixote
ID: 1844787
What I find frustrating here is that the samples I've submitted *do* work, on my browser at least.  Maybe that's why I can't get it through my skull that it's not working for you.

What browser are you using to test these samples?
0
 

Author Comment

by:LSILes
ID: 1844788
Quixote:
My browser is MSIE 3.0 [4.70.1215].  I just tried cutting and pasting both of those examples, and neither worked.

acsmith:
I just tried the setTimeout, and it worked perfectly.  =)  Finally!  Thanks so much!  Just post it as an answer, and I'll give you the points.

---LSILes
les@livingscriptures.com


0
 
LVL 10

Expert Comment

by:MasseyM
ID: 1844789
I tried to cut and paste the same thing in my browser (IE 4.x) and received a javascript error.. Just thought I'd let you know...

- Matt
0
 
LVL 1

Accepted Solution

by:
acsmith earned 30 total points
ID: 1844790
;)
0
 

Author Comment

by:LSILes
ID: 1844791
Here ya go.  Thanks again!

---LSILes
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help in good tutorials for PHP, HTML and CSS 6 40
Can't get second accordion on page to work 2 13
Asp in script 6 36
REST endpoint query with a parameter 1 16
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question