$ in JS.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    $ in JS.

    Actually my code is not running, where i am wrong?

    [CODE=HTML]
    <body onload="alert($ ('test_id').val ue);">
    <input type="text" value="ABC" id="test_id"/>
    </body>
    [/CODE]

    Please Help!
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Have you defined $ somewhere? Are you using the prototype framework?

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by acoder
      Have you defined $ somewhere? Are you using the prototype framework?
      That's what i wanted ...What is prototype framework?
      Should it be installed separately?
      Please clarify me!

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        If you just want to use the dollar function, then you don't need to include the whole prototype package which can be quite large.

        You can define it yourself, e.g.
        [code=javascript]function $() {
        var elems = [];
        for (var i = 0; i < arguments.lengt h; i++) {
        var elem = arguments[i];
        if (typeof elem == 'string')
        elem = document.getEle mentById(elem);
        if (arguments.leng th == 1)
        return elem;
        elems.push(elem );
        }
        return elems;
        }[/code]

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Originally posted by acoder
          If you just want to use the dollar function, then you don't need to include the whole prototype package which can be quite large.

          You can define it yourself, e.g.
          [code=javascript]function $() {
          var elems = [];
          for (var i = 0; i < arguments.lengt h; i++) {
          var elem = arguments[i];
          if (typeof elem == 'string')
          elem = document.getEle mentById(elem);
          if (arguments.leng th == 1)
          return elem;
          elems.push(elem );
          }
          return elems;
          }[/code]

          I understand your point.
          But whole prototype package where i can it?

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            All you had to do was search for it. Type "prototype" into your favourite search engine and hey presto! It's even included in the Offsite Links thread.

            OK, I'm feeling generous. Here it is: http://www.prototypejs.org/.

            Comment

            • dmjpro
              Top Contributor
              • Jan 2007
              • 2476

              #7
              Originally posted by acoder
              All you had to do was search for it. Type "prototype" into your favourite search engine and hey presto! It's even included in the Offsite Links thread.

              OK, I'm feeling generous. Here it is: http://www.prototypejs.org/.
              Ok Thanks!
              Basically who developed it?

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Check out the site. It should have some info.

                Comment

                Working...