Solved

Focus question...

Posted on 1998-07-21
18
277 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
 

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
jquery adding parameter to hyperlink url 8 35
javascript to html map 8 38
Flexbox in CSS3 2 25
Login area of a page 4 19
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
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 …

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now