This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

set focus

 
Kinga Cserveny
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone tell me how can I set the focus to a radio button. I need to set the focus on my jsp pages to the first field. I am using a java script function setFocus(name) to do this. I pass in the name of the field and in the function the following is done.
document.form.name.focus();
the code above does not work with the radios.
Thanks for your help.
 
Rajendar Goud
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I dont think u got any function by the name
setFocus() in javascript. u got Focus() which helps gain focus on components like Password,TextArea and Text fields. For components like RadioButton,as per my reading,focus is automatically obtained.
Raj
 
Rajendar Goud
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Correction to the previous reply.what u r using seems to be right.it should obtain focus when u use
document.form.radiobutton.focus();
But u need to be careful that ,the form and
radiobutton u r using in the syntax must be the same names as u used to define them in ur HTML .
if not u can use an array to represent these components present on the screen,like
document.forms[o].elements[o].focus();
where forms[0] indicates the first form and
elements[o] indicates the first element on the screen.
Raj
 
Kinga Cserveny
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your help. THe java script error that comes up seems to be telling me that radio button does not have the .focus() method. It works with all the other fields. But not with the radio button. I am sure that the name is correct. Any other suggestions?
Thanks for your help
 
Rajendar Goud
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
can u send me that script code ?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18272
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Technically, a radio button is a member of a group of radio button controls, so setting the FOCUS isn't proper - most GUIs expect that the same mechanism that give focus to the radio button also is going to select it, and that might not be wise.
More properly, one should select the desired radio button and give focus to the group, which should then give what amounts to a sub-focus to the selected radio button.
Most GUIs understand focus on compound controls. Java Swing, alas, does not . For specifics on JavaScript, I'd have to RTFM - the above is based on the abstract concept of focus, not the particular implementations.
 
Kinga Cserveny
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help, unfortunately I did not quite understand how I would be albe to set the focus for the group of radios.
I am not using swing.

Thanks
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As tim mentioned. Setting the focus to a radio button will automatically select it. And that's proabably why the it's not working. You may try posting to the Javascript/HTML forum for more help.
 
Kinga Cserveny
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Iam finding it impossible to insert the code into the message
 
Rajendar Goud
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
If u want to see whether the radio button is checked or not ,then u can use
document.form.radio.checked = true.
ifs that what u need focus for ,then u can get it with this also....But ,it would have been useful,if we had a look at ur code,whats ur actually trying to do ..
Raj
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic