RE: Javascript GetElementByID

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #16
    2/ not just "el.value"
    This is an example, so I've written it to show what is happening and how/why, in case of future extension.
    as if select.value wouldn’t describe what’s happening…

    Comment

    • DMsy2
      New Member
      • Dec 2009
      • 15

      #17
      It would in the restricted case of a single select.
      If however you were traversing a multiple selection list, or some other scenario, then knowing the full derivation would help.

      I'm sorry, you seem to be giving me a hard time for just trying to help people?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #18
        I'm sorry, you seem to be giving me a hard time for just trying to help people?
        I am just trying to figure out, what in this case would be the most efficient approach. and of course what the most efficient approach is, can (and probably will) always be debated. and eventually, debates can bring you further in understanding, how JavaScript works.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #19
          Don't worry, DMsy2, Dormilich means well :)

          On the CDATA, personally, I'd say that you never need it. Why? Put your JavaScript in separate files. Problem solved.

          PS. welcome to Bytes and thanks for your input!

          Comment

          • chandhseke
            New Member
            • Jun 2009
            • 92

            #20
            When i used the above code in onchange event, the textbox will get set with a value "Undefined" . Please help?

            Comment

            • chandhseke
              New Member
              • Jun 2009
              • 92

              #21
              Code:
              function addEmail() 
              { 
                  // += appends some text to something 
                  document.getElementById("textbox").value += this.value; 
              }
              I called this function within <Select>, but the text box is set with a value "Undefined" . Since we are using +=, if we select an item thrice from dropdown, then 3 times a word "undefined" gets set to the textbox "Cat_Email" .

              Please advise something?
              Last edited by Dormilich; Dec 7 '09, 05:53 PM. Reason: Please use [code] tags when posting code

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #22
                how did you attach this function to the event?

                Comment

                • chandhseke
                  New Member
                  • Jun 2009
                  • 92

                  #23
                  With the help of an on change event. I enclosed the function within <script> tags as we normally do (within <head> section) and called the function with the help of an onchange event.

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #24
                    and called the function with the help of an onchange event.
                    may I see the code for this?

                    Comment

                    • chandhseke
                      New Member
                      • Jun 2009
                      • 92

                      #25
                      Now it's working, i made a few changes to the code that you provided.

                      function addEmail()
                      {
                      document.getEle mentById("TextB ox").value += this.value;
                      }
                      I replaced += this.value with the below:
                      document.getEle mentById("TextB ox").value = document.getEle mentById("Selec t").value
                      It is working now. Thanks for your support.

                      Comment

                      • Dormilich
                        Recognized Expert Expert
                        • Aug 2008
                        • 8694

                        #26
                        ahh, yes. good ole event handling. once you understand it, it’s nearly as cool as sliced bread.

                        Comment

                        • chandhseke
                          New Member
                          • Jun 2009
                          • 92

                          #27
                          Yes, you are exactly correct. Thanks again for all your support. Your knowledge about Javascript is really outstanding.

                          Bye :)

                          Comment

                          • Dormilich
                            Recognized Expert Expert
                            • Aug 2008
                            • 8694

                            #28
                            you’ll get there, too. though not this time. (pun intended)

                            Your knowledge about Javascript is really outstanding.
                            I don’t think so, I just happen to do some proper background reading.

                            Comment

                            • chandhseke
                              New Member
                              • Jun 2009
                              • 92

                              #29
                              May i know why is that used for? I am a newbie, have no much deeper idea about JS.

                              Comment

                              • Dormilich
                                Recognized Expert Expert
                                • Aug 2008
                                • 8694

                                #30
                                you mean the "this"?
                                _______________ _

                                Comment

                                Working...