• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Simple .focus() Solution for a form

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Firstly let me wholeheartedly apologize for beating a dead horse here. I'm quite certain there is a solution for what I'm looking for somewhere on here but I've been Googling for the better part of 2 hours and haven't come to a viable answer yet. Add to the fact that I'm a javascript idiot and it's the makings for a long afternoon.

Immediate Goal: Getting a text input field to focus if it is empty (cross browser compatible)
Future Goal: Specifically I have a login and password form of which I want the function to check the email field first and if populated I want it to focus on the password field
Problem: No matter what fucntion I try I can't seem to get any fields to focus in Firefox. I currently have Firefox 3.6.13 running.
What has been tried: The page I'm working on uses an exernal .js file so typically I throw all my coding in there. For the purpose of this example let's say my form is structured like this:

and in my .js file I have the following:

and of course my opening body tag would have:


I'm probably confused with syntax or even the document model (or possibly something very complex that I'm not even seeing). It wouldn't surprise me. I do a lot of ASP coding so I often mix up the two languages at times. Now the example above was thrown together just to see if I can get the field to focus on page load. I'm not asking for a script to do what I described in the detailed description. I can probably figure that out myself. In scaling back what I was doing I figured I'd try just focusing a specified field on page load but it doesn't work in FF(x) or IE(x). My mind is just exhausted from trying to hammer out the logic. If someone would be so kind as to help an old man out it'd be greatly appreciated. I can often run with things once I understand why they do or don't work. I'm just brain fried at the moment.

Thanks for the time and consideration.
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ian. I tried your code on Firefox 3.6.13 and IE 8.0 and it's working.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic