I'm struggling with Views and Exposed form in block (id="views-exposed-form-test1-page").
I need to add onchange event on a specific select filter.

This is the code:

<select id="edit-tid" name="tid" class="form-select">

I would like to get this code:

<select id="edit-tid" name="tid" class="form-select" onchange="myfunction()">

Can anyone let me know how to do ?

Thank you

CommentFileSizeAuthor
#1 screenshot_error.jpg52.65 KBRedart

Comments

Redart’s picture

Priority: Normal » Critical
StatusFileSize
new52.65 KB

I included this code in a custom module and it seems to work.

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

if ($form_id == 'views_exposed_form' && $form['#id'] == 'views-exposed-form-test1-page') {
   
$form['tid']['#attributes'] =  array('onchange' => "myfunction();");

}
}

It seems to work.

Now, the problem is javascript. I included the script in my theme.info.
Then, i used this code:

function myfunction(){
       if ($("#tid option[value='2']").attr('selected'))
       
       {
          document.getElementById('something').style.display = "none";
       }
    } 

The result is bad, the code doesn't work.

I have attached screenshot. Can anyone let me know how to do ?

Thank you

dawehner’s picture

Priority: Critical » Normal

Add your code into a file,and you should have much less problems.

In general this is certainly not a critical question

damiankloip’s picture

You should look at the #attached form attribute. http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.ht...

This is the best way to include your script when your form is called.

damiankloip’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.