Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Problem with "document.getElementById()"

Problem with "document.getElementById()"

Scheduled Pinned Locked Moved Web Development
javascripthelptools
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Affan Toor
    wrote on last edited by
    #1

    Hi, I am having a problem in javascript, im trying to implement autocomplete on a textbox named "txtAddress". i found a JS file from net which does all processing of autocomplete using AJAX. following code in my script tag gives error: var txt=document.getElementById("txtAddress").value; or var txt=document.getElementById("txtAddress").text; I get the error document.getElementById(txtid) has no properties When I try var txt=document.getElementById("txtAddress"); txt gets the null value. I am new to javascript and dont know much about it, kindly tell me what i am missing here. Thanks in advance... Regards, Affan Ahmad Toor

    .................. QUAIDIAN FOR ONCE, QUAIDIAN FOR EVER!

    C R 2 Replies Last reply
    0
    • A Affan Toor

      Hi, I am having a problem in javascript, im trying to implement autocomplete on a textbox named "txtAddress". i found a JS file from net which does all processing of autocomplete using AJAX. following code in my script tag gives error: var txt=document.getElementById("txtAddress").value; or var txt=document.getElementById("txtAddress").text; I get the error document.getElementById(txtid) has no properties When I try var txt=document.getElementById("txtAddress"); txt gets the null value. I am new to javascript and dont know much about it, kindly tell me what i am missing here. Thanks in advance... Regards, Affan Ahmad Toor

      .................. QUAIDIAN FOR ONCE, QUAIDIAN FOR EVER!

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You're missing the bit where you need a text input with an Id of txtAddress. It doesn't exist, and so the code won't work.

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      A 1 Reply Last reply
      0
      • C Christian Graus

        You're missing the bit where you need a text input with an Id of txtAddress. It doesn't exist, and so the code won't work.

        Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        A Offline
        A Offline
        Affan Toor
        wrote on last edited by
        #3

        Thanks for reply... i checked the textbox, its 'id' & 'name' properties exists but im not sure whether it has initialized/loaded when this code executes. how can i ensure this? Regards, Affan Ahmad Toor

        .................. QUAIDIAN FOR ONCE, QUAIDIAN FOR EVER!

        C 1 Reply Last reply
        0
        • A Affan Toor

          Thanks for reply... i checked the textbox, its 'id' & 'name' properties exists but im not sure whether it has initialized/loaded when this code executes. how can i ensure this? Regards, Affan Ahmad Toor

          .................. QUAIDIAN FOR ONCE, QUAIDIAN FOR EVER!

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          View the source of the page itself. For example, if this is an ASP.NET server control, the Id is autogenerated for the client side and is not what you see in your code.

          Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          1 Reply Last reply
          0
          • A Affan Toor

            Hi, I am having a problem in javascript, im trying to implement autocomplete on a textbox named "txtAddress". i found a JS file from net which does all processing of autocomplete using AJAX. following code in my script tag gives error: var txt=document.getElementById("txtAddress").value; or var txt=document.getElementById("txtAddress").text; I get the error document.getElementById(txtid) has no properties When I try var txt=document.getElementById("txtAddress"); txt gets the null value. I am new to javascript and dont know much about it, kindly tell me what i am missing here. Thanks in advance... Regards, Affan Ahmad Toor

            .................. QUAIDIAN FOR ONCE, QUAIDIAN FOR EVER!

            R Offline
            R Offline
            RichardGrimmer
            wrote on last edited by
            #5

            It's about parentesis more than likely - try the following: var txt=(document.getElementById("txtAddress")).value; "Knock me down, I'll get straight back up again, I'll come back stronger than a powered up pacman" (Lilly Allen / Kaiser Chiefs)

            G V 2 Replies Last reply
            0
            • R RichardGrimmer

              It's about parentesis more than likely - try the following: var txt=(document.getElementById("txtAddress")).value; "Knock me down, I'll get straight back up again, I'll come back stronger than a powered up pacman" (Lilly Allen / Kaiser Chiefs)

              G Offline
              G Offline
              Guffa
              wrote on last edited by
              #6

              RichardGrimmer wrote:

              It's about parentesis more than likely - try the following: var txt=(document.getElementById("txtAddress")).value;

              Actually very much less than likely. The extra parentheses are completely superflous.

              --- single minded; short sighted; long gone;

              R 1 Reply Last reply
              0
              • G Guffa

                RichardGrimmer wrote:

                It's about parentesis more than likely - try the following: var txt=(document.getElementById("txtAddress")).value;

                Actually very much less than likely. The extra parentheses are completely superflous.

                --- single minded; short sighted; long gone;

                R Offline
                R Offline
                RichardGrimmer
                wrote on last edited by
                #7

                Ah well - you live and learn :)

                "Knock me down, I'll get straight back up again, I'll come back stronger than a powered up pacman" (Lilly Allen / Kaiser Chiefs)

                1 Reply Last reply
                0
                • R RichardGrimmer

                  It's about parentesis more than likely - try the following: var txt=(document.getElementById("txtAddress")).value; "Knock me down, I'll get straight back up again, I'll come back stronger than a powered up pacman" (Lilly Allen / Kaiser Chiefs)

                  V Offline
                  V Offline
                  vanhawk
                  wrote on last edited by
                  #8

                  I think this is the right syntax var txt=(document.getElementById("txtAddress").value);

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups