Web Analytics Made Easy -
StatCounter focusing on an image input - CodingForum

Announcement

Collapse
No announcement yet.

focusing on an image input

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • focusing on an image input

    I am trying to focus on an input type="image" when the page loads with something like...

    Code:
    <body onLoad="document.form1.imageTag.focus();">
    I've tried many variations to the script, but when I try to focus on an image input, it just doesn't work. I get an error that it's null or not an object. However, if I change it's type from image to text, it works fine. Any ideas? Thanks.

  • #2
    what browser does that happen in?
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

    Comment


    • #3
      Internet Explorer

      Explorer version 6.0.2600.

      Comment


      • #4
        well, i don't know what to tell you. as far as i know, that should be working. can we see the code you're working with?
        bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

        i am a loser geek, crazy with an evil streak,
        yes i do believe there is a violent thing inside of me.

        Comment


        • #5
          I have the same Problem.

          When I dump my forms Elements with JavaScript I get:

          name: form[save] index: 10
          name: form[refresh] index: 9
          name: page index: 8
          name: form[screenName] index: 7
          name: form[websiteUrl] index: 6
          name: form[websiteName] index: 5
          name: form[movieName] index: 4
          name: form[bookAuthor] index: 3
          name: form[bookName] index: 2
          name: form[bandName] index: 1
          name: form[quote] index: 0

          But there are no <input type="image">'s in there, I have a bunch of them :/

          Comment


          • #6
            Sez right here that input type=image are not part of the collection.

            Give it an ID and access it via document.getElementById()
            My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
            “Minds are like parachutes. They don't work unless they are open”
            “Maturity is simply knowing when to not be immature”

            Comment


            • #7
              I can't seem to be able to focus an element by its Id.


              that doesnt do it for some reason:
              Code:
              <html>
              <body>
              
              <form>
                <input name="realName" id="realName">
              </form>
              
              <script language="JavaScript">
              <!--
                document.getElementById("realName").focus();
              -->
              </script>
              
              </body>
              </html>

              Comment


              • #8
                Works just peachy for me.

                Browser?
                My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
                “Minds are like parachutes. They don't work unless they are open”
                “Maturity is simply knowing when to not be immature”

                Comment


                • #9
                  IE 6

                  Comment


                  • #10
                    well... its working now.. strange. it didnt work when i posted that. or it seemed not to be working. strange. sorry

                    maybe im just stupid

                    Comment


                    • #11
                      Well. it didnt work again for some reason on the regular form I'm using (The one i posted was just to show)

                      What I had to do is:
                      Code:
                       document.getElementById("nameHere").focus();
                       window.focus();   <------- THIS
                      I dont know why, but now it works

                      Comment

                      Working...
                      X