Loading ...
Sorry, an error occurred while loading the content.
 

Using Element to get Textarea value

Expand Messages
  • tropeanojohn
    I am trying to use the new Element to grab the value of a textarea. -- snippet -- // textarea id= code var el = new YAHOO.util.Element( code ); which does
    Message 1 of 8 , Feb 27, 2007
      I am trying to use the new Element to grab the value of a textarea.


      -- snippet --

      // textarea id="code"
      var el = new YAHOO.util.Element('code');

      which does obtain a reference to *some* object, but I can't get the value.

      Any ideas?

      Thanks
    • Matt Sweeney
      Hi, You can use the get method to retrieve the value attribute of the textarea. Something like: var el = new YAHOO.util.Element( foo );
      Message 2 of 8 , Feb 27, 2007
        Hi,

        You can use the "get" method to retrieve the "value" attribute of the
        textarea.

        Something like:

        var el = new YAHOO.util.Element('foo');

        el.on('contentReady', function() {
        alert(this.get('value'));
        });

        Matt

        tropeanojohn wrote:
        > I am trying to use the new Element to grab the value of a textarea.
        >
        >
        > -- snippet --
        >
        > // textarea id="code"
        > var el = new YAHOO.util.Element('code');
        >
        > which does obtain a reference to *some* object, but I can't get the value.
        >
        > Any ideas?
        >
        > Thanks
        >
        >
        >
        >
        >
        > Yahoo! Groups Links
        >
        >
        >
        >
        >
        >
        >
      • dav.glass@yahoo.com
        John -- You should be able to do this: // textarea id= code var el = new YAHOO.util.Element( code ); el.get( value ); Hope that helps 8-) Dav Dav Glass
        Message 3 of 8 , Feb 27, 2007
          John --

          You should be able to do this:

          // textarea id="code"
          var el = new YAHOO.util.Element('code');
          el.get('value');

          Hope that helps 8-)
          Dav
           
          Dav Glass
          dav.glass@...
          blog.davglass.com


          + Windows: n. - The most successful computer virus, ever. +
          + A computer without a Microsoft operating system is like a dog
          without bricks tied to its head +
          + A Microsoft Certified Systems Engineer is to computing what a
          McDonalds Certified Food Specialist is to fine cuisine +


          ----- Original Message ----
          From: tropeanojohn <tropeanojohn@...>
          To: ydn-javascript@yahoogroups.com
          Sent: Tuesday, February 27, 2007 7:20:51 PM
          Subject: [ydn-javascript] Using Element to get Textarea value

          I am trying to use the new Element to grab the value of a textarea.


          -- snippet --

          // textarea id="code"
          var el = new YAHOO.util.Element('code');

          which does obtain a reference to *some* object, but I can't get the value.

          Any ideas?

          Thanks



          ------------------------ Yahoo! Groups Sponsor --------------------~-->
          Something is new at Yahoo! Groups.  Check out the enhanced email design.
          http://us.click.yahoo.com/kOt0.A/gOaOAA/yQLSAA/edFolB/TM
          --------------------------------------------------------------------~->


          Yahoo! Groups Links

          <*> To visit your group on the web, go to:
              http://groups.yahoo.com/group/ydn-javascript/

          <*> Your email settings:
              Individual Email | Traditional

          <*> To change settings online go to:
              http://groups.yahoo.com/group/ydn-javascript/join
              (Yahoo! ID required)

          <*> To change settings via email:
              mailto:ydn-javascript-digest@yahoogroups.com
              mailto:ydn-javascript-fullfeatured@yahoogroups.com

          <*> To unsubscribe from this group, send an email to:
              ydn-javascript-unsubscribe@yahoogroups.com

          <*> Your use of Yahoo! Groups is subject to:
              http://docs.yahoo.com/info/terms/


        • tropeanojohn
          I tried. Not working. Here is all my code.
          Message 4 of 8 , Feb 27, 2007
            I tried. Not working.

            Here is all my code.

            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
            <title>Untitled Document</title>
            <link rel="stylesheet" type="text/css"
            href="http://yui.yahooapis.com/2.2.0/build/reset-fonts-grids/reset-fonts-grids.css">


            <script type="text/javascript"
            src="http://yui.yahooapis.com/2.2.0/build/utilities/utilities.js"></script>

            <script type="text/javascript"
            src="http://yui.yahooapis.com/2.2.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>

            <script type="text/javascript"
            src="http://yui.yahooapis.com/2.2.0/build/element/element-beta-min.js"></script>
            <script type="text/javascript"
            src="http://yui.yahooapis.com/2.2.0/build/button/button-beta-min.js"></script>



            <script type="text/javascript">

            var Example = function(){

            return{

            init : function(){

            var el = new YAHOO.util.Element('doIt');

            /* Attach click handler to button */
            el.on('click', function() {

            /* Get Value from Textarea */
            var ta = new YAHOO.util.Element('code');
            ta.get('value');
            alert(ta);

            });

            }

            };

            }();

            YAHOO.util.Event.onAvailable('doc',Example.init, Example, true);

            </script>


            </head>

            <body id="doc">
            <h1>Convert</h1>
            <textarea name="myTextArea" cols="50" rows="6" id="myTextArea"></textarea>
            <p/>
            <input type="button" id="doIt" value="Do it" />

            </body>
            </html>

            What am I doing wrong? How do I obtain a handle to the DOM reference
            of an object?

            Thank you.
          • dav.glass@yahoo.com
            John -- From you included code this: /* Get Value from Textarea */ var ta = new YAHOO.util.Element( code ); ta.get( value ); alert(ta); Should be this: /* Get
            Message 5 of 8 , Feb 27, 2007
              John --

              From you included code this:
               /* Get Value from Textarea */
                              var ta = new YAHOO.util.Element('code');
                              ta.get('value');
                              alert(ta);


              Should be this:

               /* Get Value from Textarea */
                              var ta = new YAHOO.util.Element('myTextArea');
                              var data = ta.get('value');
                              alert(data);
               
              Dav Glass
              dav.glass@...
              blog.davglass.com


              + Windows: n. - The most successful computer virus, ever. +
              + A computer without a Microsoft operating system is like a dog
              without bricks tied to its head +
              + A Microsoft Certified Systems Engineer is to computing what a
              McDonalds Certified Food Specialist is to fine cuisine +


              ----- Original Message ----
              From: tropeanojohn <tropeanojohn@...>
              To: ydn-javascript@yahoogroups.com
              Sent: Tuesday, February 27, 2007 8:22:10 PM
              Subject: [ydn-javascript] Re: Using Element to get Textarea value

              I tried. Not working.

              Here is all my code.

              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
              <html xmlns="http://www.w3.org/1999/xhtml";>
              <head>
              <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
              <title>Untitled Document</title>
              <link rel="stylesheet" type="text/css"
              href="http://yui.yahooapis.com/2.2.0/build/reset-fonts-grids/reset-fonts-grids.css";>


              <script type="text/javascript"
              src="http://yui.yahooapis.com/2.2.0/build/utilities/utilities.js"></script>

              <script type="text/javascript"
              src="http://yui.yahooapis.com/2.2.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>

              <script type="text/javascript"
              src="http://yui.yahooapis.com/2.2.0/build/element/element-beta-min.js"></script>
              <script type="text/javascript"
              src="http://yui.yahooapis.com/2.2.0/build/button/button-beta-min.js"></script>



              <script type="text/javascript">

              var Example = function(){

                  return{
                  
                      init : function(){
                      
                          var el = new YAHOO.util.Element('doIt');
                          
                          /* Attach click handler to button */
                          el.on('click', function() {
                                 
                              /* Get Value from Textarea */
                              var ta = new YAHOO.util.Element('code');
                              ta.get('value');
                              alert(ta);
                              
                          });
                      
                      }
                      
                  };

              }();

              YAHOO.util.Event.onAvailable('doc',Example.init, Example, true);

              </script>


              </head>

              <body id="doc">
              <h1>Convert</h1>
              <textarea name="myTextArea" cols="50" rows="6" id="myTextArea"></textarea>
              <p/>
              <input type="button" id="doIt" value="Do it" />

              </body>
              </html>

              What am I doing wrong? How do I obtain a handle to the DOM reference
              of an object?

              Thank you.



              ------------------------ Yahoo! Groups Sponsor --------------------~-->
              Check out the new improvements in Yahoo! Groups email.
              http://us.click.yahoo.com/4It09A/fOaOAA/yQLSAA/edFolB/TM
              --------------------------------------------------------------------~->


              Yahoo! Groups Links

              <*> To visit your group on the web, go to:
                  http://groups.yahoo.com/group/ydn-javascript/

              <*> Your email settings:
                  Individual Email | Traditional

              <*> To change settings online go to:
                  http://groups.yahoo.com/group/ydn-javascript/join
                  (Yahoo! ID required)

              <*> To change settings via email:
                  mailto:ydn-javascript-digest@yahoogroups.com
                  mailto:ydn-javascript-fullfeatured@yahoogroups.com

              <*> To unsubscribe from this group, send an email to:
                  ydn-javascript-unsubscribe@yahoogroups.com

              <*> Your use of Yahoo! Groups is subject to:
                  http://docs.yahoo.com/info/terms/


            • tropeanojohn
              I really must be doing something wrong. http://missioncriticalmedia.com/trope/yui/ I copied and pasted your code. Still getting undefined. ???
              Message 6 of 8 , Feb 27, 2007
                I really must be doing something wrong.

                http://missioncriticalmedia.com/trope/yui/


                I copied and pasted your code. Still getting undefined.

                ???
              • dav.glass@yahoo.com
                Your not alone 8-) http://blog.davglass.com/files/yui/trope/ I can t get it to behave either.. Not sure what s going on, Matt do you have any suggestions? Dav
                Message 7 of 8 , Feb 27, 2007
                  Your not alone 8-)

                  http://blog.davglass.com/files/yui/trope/

                  I can't get it to behave either..

                  Not sure what's going on, Matt do you have any suggestions?

                  Dav
                   
                  Dav Glass
                  dav.glass@...
                  blog.davglass.com


                  + Windows: n. - The most successful computer virus, ever. +
                  + A computer without a Microsoft operating system is like a dog
                  without bricks tied to its head +
                  + A Microsoft Certified Systems Engineer is to computing what a
                  McDonalds Certified Food Specialist is to fine cuisine +


                  ----- Original Message ----
                  From: tropeanojohn <tropeanojohn@...>
                  To: ydn-javascript@yahoogroups.com
                  Sent: Tuesday, February 27, 2007 8:47:20 PM
                  Subject: [ydn-javascript] Re: Using Element to get Textarea value

                  I really must be doing something wrong.

                  http://missioncriticalmedia.com/trope/yui/


                  I copied and pasted your code. Still getting undefined.

                  ???



                  ------------------------ Yahoo! Groups Sponsor --------------------~-->
                  Yahoo! Groups gets a make over. See the new email design.
                  http://us.click.yahoo.com/hOt0.A/lOaOAA/yQLSAA/edFolB/TM
                  --------------------------------------------------------------------~->


                  Yahoo! Groups Links

                  <*> To visit your group on the web, go to:
                      http://groups.yahoo.com/group/ydn-javascript/

                  <*> Your email settings:
                      Individual Email | Traditional

                  <*> To change settings online go to:
                      http://groups.yahoo.com/group/ydn-javascript/join
                      (Yahoo! ID required)

                  <*> To change settings via email:
                      mailto:ydn-javascript-digest@yahoogroups.com
                      mailto:ydn-javascript-fullfeatured@yahoogroups.com

                  <*> To unsubscribe from this group, send an email to:
                      ydn-javascript-unsubscribe@yahoogroups.com

                  <*> Your use of Yahoo! Groups is subject to:
                      http://docs.yahoo.com/info/terms/


                • Matt Sweeney
                  ... This is a timing issue. Due to the asynchronous nature of onAvailable/onContentReady (which Element uses under the hood), your call to get is being
                  Message 8 of 8 , Feb 28, 2007
                    tropeanojohn wrote:
                    > I tried. Not working.
                    >
                    >
                    This is a timing issue. Due to the asynchronous nature of
                    onAvailable/onContentReady (which Element uses under the hood), your
                    call to get is being executed before the Element is actually ready.

                    You can either defer your calls to "get" until "contentReady" fires (per
                    my example), or create your Element instance outside of the click
                    handler so it will be ready onclick.

                    Matt
                  Your message has been successfully submitted and would be delivered to recipients shortly.