This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How do I return focus to previous field

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We are creating a time entry screen, so lots of text fields.
We want to edit the value entered, so are trying onBlur or onChange events. If an error is found (text field1), we want to set the focus on the field (text field1) in error. The problem is when we do that, it sets focus on the next text field in line (text field2), not the one in error.
How can we set the focus on the field they tabbed off of?
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check the tab index of all your boxes and organize them in a cronological order from top to bottom then when setting focus to that specific one it will go to the next index in the hirearchi.
 
Kerry Shannon
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry, my question amy not have been clear.
How do I set focus on the field I just changed?
We have the tab order set up and it works.
Our problem is: We do the onBlur or onChange, call a function, and in the function find an error. We have an alert, then set focus. When we test, the error is found so the call of the function and the function itself works. But, the focus is not on the changed field. It is on the next field in tab order.
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kerry
Depending on what your method call looks like you can do a couple of things:
if you are passing the actual filed to the function you can use this to set the focus back on the field, something like this:
in the html
<input type=text onblur='verify(this);'>
then the function would look like this:
function verify(item){
// check the value
// if good just return, else
alert("The data you entered is wrong. Please fix it.");
item.select();
item.focus();
If your using a generic verification function then when you loop through the items on the page and find the right one you can just use its name to set the focus on it.
document.formName.fieldName.focus();
hope that helps
Dave
 
Kerry Shannon
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Something is not working. We can trace the error thru the function, but it does not return focus to the field in error. It goes on to the next field.
We are calling the function in an HTML onChange event:
onChange="checkTime(StartTime<%=x%> )"

Here's the javascript function:
function checkTime(timeObj)
{
alert("In Function")
fieldlength=timeObj.value.length
if (fieldlength == 0)
{
timeObj.select()
timeObj.focus()
}
if (fieldlength < 7)
{
alert(fieldlength)
alert("Invalid format! Try this format-- hh:mm AM or hh:mm PM")
timeObj.select(this)
timeObj.focus(this)
return false
}
return true
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic