How do I add javascript to a module? I'm building a module with a basic form. This form has some js attached to it that I want to keep in the module, so that it's not cluttering my regular scripts file. How do I add it to my module?

I tried to add this is in my .module file but no luck. 

function mymodule_init() {
drupal_add_js(drupal_get_path('module', 'mymodule') .'/myscriptfile.js');
}


What should I do?
You can declare the script file inside mymodule.info with

scripts[] = myscriptfile.js


This way it's gonna be included in every page of your site, exactly the same result you obtain adding it manually to hook_init.

In case you want it only when you render a form, add this to the form declaration

$form['#attached']['js'][] = drupal_get_path('module', 'mymodule).'myscriptfile.js';