Link to home
Start Free TrialLog in
Avatar of LSILes
LSILes

asked on

Focus question...

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.  =)
Avatar of Christian_Wenz
Christian_Wenz

just guessing, but have you tried document.elementName.focus() ?
Avatar of LSILes

ASKER

Just tried it....   didn't work for me.  Thanks for the guess though.
if they are in the same form, then you can do it this way:

<inut type="radio" ... onClick="this.form.keyword.focus()">
Avatar of LSILes

ASKER

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
Try this:

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

Good Luck,
Speaker                  
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>
Avatar of LSILes

ASKER

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
could you post a URL or the code?
Avatar of LSILes

ASKER

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
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.
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.
Avatar of LSILes

ASKER

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
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)
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?
Avatar of LSILes

ASKER

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


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
ASKER CERTIFIED SOLUTION
Avatar of acsmith
acsmith

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LSILes

ASKER

Here ya go.  Thanks again!

---LSILes