By goldkey266 on
Hi,
I am trying to do something very simple and I can't find the way to do it.
I want to create a form with one button "Print" that when pressed will open the windows print dialog.
I created a javascript file called printer_window.js
I added the javascript file using the module hook_init like this
function my_module_init() {
drupal_add_js(drupal_get_path('module', 'my_module') . '/printer_window.js');
}
function my_form_submit($form, &$form_state) {
}
My javascript function name is OpenPrintWindow
My question is how do I call the Javascript function from function my_form_submit?
I spent the last 2 days looking for an example and could not find anything. The drupal documentation about javascript is pretty confusing
can someone please help?
Comments
FOUND IT!!!!!!!!!!!!!!
Form action is getting set & submit button reloads the page
I tried what you have done. But clicking submit button reloads the page. Looking at the source, the form action is getting set to the present page. And even if I set form['#action'] = '', nothing is changing.
Am I missing anything?
Regards,
Sid
you need to return a false
you need to return a false value from your javascript function. You will do that inside the javascript script.
Contact me to contract me for D7 -> D10/11 migrations.
Set return false from the module
Thanx Jay. I didnt think of the return false option.
However, I couldnt set the return false from the JavaScript. But I succeeded in setting the return false from within the module itself. Something like this:
It works
Thank you for posting this. I spent hours trying to figure this out.