+6 votes
572 views
asked in Programming by (10.6k points)

Hi all,

I need a button to show/hide a div in add content window on Drupal. I add button but it acts as submit so when I press the button page reloads and I cannot call javascript. I searched over internet however could not find a possible solution. Can you help me?

1 Answer

+7 votes
answered by (15.2k points)

First add a button :

I assume that you want to add into add content / edit content form. create a module and add this code

 

function YOUR_MODULE_NAME_form_alter(&$form, $form_state, $form_id) {

if(strpos($form_id,"_node_form")>0) //katalog göster gizle butonudur, iframe açıp kapatır, getemfix.js dosyasını kullanır
{
$jslink = "return (katalogshowhide());"; // ta ta ta return is the trick here, we return false
    $form['katalog-goster-butonu'] = array(
'#type' => 'submit',
'#value' => t('Katalog Göster'), 
'#attributes' => array('onclick' => $jslink),   //we call function here
'#executes_submit_callback' => FALSE              
);
}
}
 
paste this is YOUR_MODULE_NAME.js file
function katalogshowhide()
{
if ( jQuery("#fileselect").is(':visible')!=true )
{
if(jQuery('#fileselect').length > 0) jQuery('#fileselect').remove();
jQuery('#fileselect').show();
}
else
{
jQuery("#fileselect").hide();
}
return false;
}
 
that's all
 

 


Ask a Question
Welcome to WikiTechSolutions where you can ask questions and receive answers from other members of the community.

You can ask a question without registration.

Categories

...