By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,481 Members | 1,713 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,481 IT Pros & Developers. It's quick & easy.

$ in JS.

dmjpro
100+
P: 2,476
Actually my code is not running, where i am wrong?

Expand|Select|Wrap|Line Numbers
  1. <body onload="alert($('test_id').value);">
  2. <input type="text" value="ABC" id="test_id"/>
  3. </body>
  4.  
Please Help!
Jul 20 '08 #1
Share this Question
Share on Google+
7 Replies


acoder
Expert Mod 15k+
P: 16,027
Have you defined $ somewhere? Are you using the prototype framework?
Jul 20 '08 #2

dmjpro
100+
P: 2,476
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!
Jul 20 '08 #3

acoder
Expert Mod 15k+
P: 16,027
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.
Expand|Select|Wrap|Line Numbers
  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. }
Jul 20 '08 #4

dmjpro
100+
P: 2,476
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.
Expand|Select|Wrap|Line Numbers
  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?
Jul 20 '08 #5

acoder
Expert Mod 15k+
P: 16,027
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/.
Jul 20 '08 #6

dmjpro
100+
P: 2,476
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?
Jul 20 '08 #7

acoder
Expert Mod 15k+
P: 16,027
Check out the site. It should have some info.
Jul 20 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.