?
Solved

Focus question...

Posted on 1998-07-21
18
Medium Priority
?
307 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 90 total points
ID: 1844790
;)
0
 

Author Comment

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

---LSILes
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Suggested Courses

752 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