Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

$ in JS.

Question posted by: dmjpro (Lives Here) on July 20th, 2008 10:55 AM
Actually my code is not running, where i am wrong?

Code: ( text )
  1. <body onload="alert($('test_id').value);">
  2. <input type="text" value="ABC" id="test_id"/>
  3. </body>


Please Help!
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
acoder's Avatar
acoder
Site Moderator
10,933 Posts
July 20th, 2008
11:04 AM
#2

Re: $ in JS.
Have you defined $ somewhere? Are you using the prototype framework?

Reply
dmjpro's Avatar
dmjpro
Lives Here
2,079 Posts
July 20th, 2008
11:13 AM
#3

Re: $ in JS.
Quote:
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!

Reply
acoder's Avatar
acoder
Site Moderator
10,933 Posts
July 20th, 2008
11:45 AM
#4

Re: $ in JS.
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: ( text )
  1. function $() {
  2.     var elems = [];
  3.     for (var i = 0; i < arguments.length; i++) {
  4.         var elem = arguments[i];
  5.         if (typeof elem == 'string')
  6.             elem = document.getElementById(elem);
  7.         if (arguments.length == 1)
  8.             return elem;
  9.         elems.push(elem);
  10.     }
  11.     return elems;
  12. }

Reply
dmjpro's Avatar
dmjpro
Lives Here
2,079 Posts
July 20th, 2008
01:29 PM
#5

Re: $ in JS.
Quote:
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: ( text )
  1. function $() {
  2.     var elems = [];
  3.     for (var i = 0; i < arguments.length; i++) {
  4.         var elem = arguments[i];
  5.         if (typeof elem == 'string')
  6.             elem = document.getElementById(elem);
  7.         if (arguments.length == 1)
  8.             return elem;
  9.         elems.push(elem);
  10.     }
  11.     return elems;
  12. }



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

Reply
acoder's Avatar
acoder
Site Moderator
10,933 Posts
July 20th, 2008
03:08 PM
#6

Re: $ in JS.
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/.

Reply
dmjpro's Avatar
dmjpro
Lives Here
2,079 Posts
July 20th, 2008
03:17 PM
#7

Re: $ in JS.
Quote:
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?

Reply
acoder's Avatar
acoder
Site Moderator
10,933 Posts
July 20th, 2008
04:10 PM
#8

Re: $ in JS.
Check out the site. It should have some info.

Reply
Reply
Not the answer you were looking for? Post your question . . .
183,630 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top Javascript / DHTML / Ajax Forum Contributors