Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 322
  • Last Modified:

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.  =)
0
LSILes
Asked:
LSILes
  • 7
  • 5
  • 3
  • +3
1 Solution
 
Christian_WenzCommented:
just guessing, but have you tried document.elementName.focus() ?
0
 
LSILesAuthor Commented:
Just tried it....   didn't work for me.  Thanks for the guess though.
0
 
QuixoteCommented:
if they are in the same form, then you can do it this way:

<inut type="radio" ... onClick="this.form.keyword.focus()">
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
LSILesAuthor Commented:
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
 
speakerCommented:
Try this:

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

Good Luck,
Speaker                  
0
 
QuixoteCommented:
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
 
LSILesAuthor Commented:
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
 
QuixoteCommented:
could you post a URL or the code?
0
 
LSILesAuthor Commented:
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
 
acsmithCommented:
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
 
QuixoteCommented:
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
 
LSILesAuthor Commented:
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
 
acsmithCommented:
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
 
QuixoteCommented:
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
 
LSILesAuthor Commented:
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
 
MasseyMCommented:
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
 
acsmithCommented:
;)
0
 
LSILesAuthor Commented:
Here ya go.  Thanks again!

---LSILes
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

  • 7
  • 5
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now