Help regarding Javascript In drupal
shipoo - October 14, 2008 - 06:29
hi
I m new to drupal..I want to know whether nybody could help me out in embedding javascript file in one module..also i wnt to know how to refer to the form elemnts in drupal form as how we culd do it in normal javascript like document.form.checkbox in drupal...Please help me..
Thank u...

*sigh*
http://drupal.org/search/node/javascript+in+drupal
.dan.
if you are asking a question you think should be documented, please provide a link to the handbook where you think the answer should be found.
| http://www.coders.co.nz/ |
reply
Thanks for replying ..I have gone thrrough that page but still have some doubts like
1)my javascript file is in drupal/modules/ecommerce/cart/js/check.js
so the statement which i need to add in the cart.module will be drupal_add_js ('./js/check.js')...???and in which hook i can mention it..???
2)also i wnt to knw how to check whther the check box is clicked or not in that form..??? pls reply
Than you...
Adding JavaScript to your theme or module
Actually read the handbook there !
.dan.
if you are asking a question you think should be documented, please provide a link to the handbook where you think the answer should be found.
| http://www.coders.co.nz/ |
1) Don't change existing
1) Don't change existing modules, it will make upgrading a pain. Put your drupal_add_js() in a custom module or in your template.php.
2) Assuming you use jQuery for your javascript: read the jQuery documentation (http://docs.jquery.com/Main_Page) or search google to find this (Drupal :-)) page, for example: http://jquery.open2space.com/node/15
3) if you just behave as a kind and respectful forum user, "pls reply" will not be necessary.
JQuery to javascript
Actually m thorough with javascript and not JQuery so is it that i have to use JQuery for drupal forms...???I cannot use simple Javascript like say i want to put javascript code for one form.so I cannot put in page.tpl.php....???And incase if yes then how do i refer to elemnts in drupal as we dont have form name for drupal...how i will b able to use something like document.form.checkbox.value.....???
thank u...
You can use your own
You can use your own javascript code, no problems. Many developers like jQuery because it allows you to write powerful, cross-browser javascript with very little code. I'd advice you to look into it and see if you like the idea behind jQuery. But plain javascript is fine too.
The drupal_add_js function is not limited to jQuery, it's meant to add all sorts of javascript. It's strongly recommended to use drupal_add_js instead of adding the javascript directly to your page.tpl.php.
ok but incase of that where
ok but incase of that where do i have to put the add drupal_add_js () statement ..??in which of the hook of my module..???and what about refering to particular elements in the form...???how will i do that..???because i searched a lot but culdnt find to refering to like checkbox in drupal throgh normal javascript code like document.form.checkbox.value as there is no form name ....
Thank u..
Dman gave you the link to
Dman gave you the link to the handbook page about drupal_add_js. Why not read it?
I can't help you with your javascript question - you said you're good at javascript, right? I'm not. When I need javascript, I use jQuery.
And by the way, ask your
And by the way, ask your question only once, in the most appropriate forum. No cross posting please!
thank you
thanks a lot for that...and also sorry for cross posting...