Hi,
I want to add a button to the content edit section using hook_form_alter and run a js function(openFileBrowser) to open the IMCE.

function openFileBrowser() {
  window.open('/?q=imce&app=myApp|url@urlField', '', 'width=760,height=560,resizable=1');
}

Is the following method right? (It doesn't work), what is the solution?

    $form['new']['button'] = array(
      '#type' => 'button',
	  '#value' => 'Browse',
	  '#onclick'=>'openFileBrowser()',
or 	  '#submit' =>'openFileBrowser()', 
    );

thanks in advance ...

Comments

dragon2000’s picture

I used drupal_add_js to implement the function but it still doesn't work:

function openFileBrowser() {
drupal_add_js("window.open('/?q=imce&app=myApp|url@urlField', '', 'width=760,height=560,resizable=1');", 'inline');
}

please help me...

ufku’s picture

$form['custom_markup'] = array(
  '#type' => 'markup',
  '#value' => '<input type="button" value="Browse" onclick="window.open(\'/?q=imce&app=myApp|url@urlField\', \'\', \'width=760,height=560,resizable=1\'); return false;">',
);
abhishek_patel’s picture

Great buddy,
it works nice..
Thanks.

abhishek.cmswebsiteservices’s picture

Drupal Approach

$form['new']['submit'] = array(
'#type' => 'submit',
'#value' => 'Browse',
'#attribute'=>array("onClick"=>"openFileBrowser()")
);