how to getAttribute of value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maminx
    New Member
    • Jul 2008
    • 77

    how to getAttribute of value

    Hello all,, i have a question, please help me to find out

    i have this script (in js function)
    [CODE=javascript]var td = document.create Element('td');
    var p = document.create Element('p');
    var label = document.create Element('label' );
    var span = document.create Element('span') ;
    var theTextarea = document.create Element('textar ea');
    theTextarea.set Attribute('name ', 'work_descripti on');
    theTextarea.set Attribute('valu e','');
    span.appendChil d(theData);
    label.appendChi ld(span);
    label.appendChi ld(theTextarea) ;
    p.appendChild(l abel);
    td.appendChild( p);
    row.appendChild (td);
    theTextarea.onc hange = function(){theT extarea.getAttr ibute('value')) ;}
    [/CODE]
    With command "theTextarea.on change...", i want to get a value from html object form (textarea) that has been input by user.
    But with that command, i always get null (empty string) value.

    Any idea??thanks
    Last edited by acoder; Jul 14 '08, 09:59 AM. Reason: Added [code] tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    theTextarea should be replaced by 'this':[CODE=javascript]
    theTextarea.onc hange = function(){this .getAttribute(' value'));}[/CODE]
    PS. please use code tags when posting code. See How to Ask a Question.

    Comment

    • maminx
      New Member
      • Jul 2008
      • 77

      #3
      ok thanks, it works perfectly..

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        And remove the extra bracket after ('value')

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Originally posted by hsriat
          And remove the extra bracket after ('value')
          Oh, I didn't see that. Thanks for pointing out :)

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by maminx
            ok thanks, it works perfectly..
            Glad to hear it. If you have any more questions, just post back to the forum.

            PS. welcome to the site. I notice that you've just joined. Happy posting!

            Comment

            • hsriat
              Recognized Expert Top Contributor
              • Jan 2008
              • 1653

              #7
              Originally posted by acoder
              Oh, I didn't see that. Thanks for pointing out :)
              You are welcome. :)
              (Perhaps this is the first time)

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Lol, there's always a first time for everything ;)

                Comment

                • maminx
                  New Member
                  • Jul 2008
                  • 77

                  #9
                  actually, with that command, i want to make a validation. So if the object textarea is empty or user doesn't input text to the object textarea, than i will generate an alert ("required field...")..

                  and of course, first i'd like to get a value that user input from the textarea object with this script

                  theTextarea.onc hange = function(){
                  alert(this.getA ttribute('value '));
                  }


                  It is works perfectly with that command, and no error founded, but the alert is shown if user input any character to the textarea object.
                  If user didn't input a value (it means user press "tab" to jump from the textarea object to another object), the alert of value won't come out.

                  So the alert is shown if only the user input a value to the textarea object.

                  any idea?

                  Comment

                  • hsriat
                    Recognized Expert Top Contributor
                    • Jan 2008
                    • 1653

                    #10
                    I guess you are in need of onblur event.

                    Comment

                    • maminx
                      New Member
                      • Jul 2008
                      • 77

                      #11
                      i have changed into onblur event, but still, it won't work..more advice?

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        You have to check the input. Check if it's empty or whatever other checks you want to make. Note though that onblur can sometimes fire unexpectedly, so I wouldn't use alerts (which can be annoying). I'd use DHTML to show a message next to the field.

                        Comment

                        Working...