Questions tagged [javascript]

Use it for questions about JavaScript code that is very specific for Drupal.

Filter by
Sorted by
Tagged with
34
votes
4answers
44k views

How do I update jQuery to the latest version I can download?

I'm using Drupal 7, which uses jQuery 1.4 as default? How can I update it to the latest version (currently 1.7)?
42
votes
3answers
47k views

how to send variable from .php file to .js file?

I hope someone is able to help me. The problem is the following one: 1)I have module in which a assign the variable in order to send to the template file php.tpl <?php ... $testvar="Hello from ...
9
votes
2answers
19k views

How do I add JavaScript to a site?

How can I add JavaScript and CSS to my site?
53
votes
2answers
39k views

Better understanding of Drupal behaviors

I read about Drupal behaviors today, and I tried writing the following code. (function ($) { Drupal.behaviors.mymodule = { attach: function (context, settings) { $('#mymodule_id', ...
30
votes
2answers
33k views

Eliminate render-blocking JavaScript and CSS in above-the-fold content

I am building a Drupal 7 site. These are some of the modules I use: Adaptivetheme (theme), Views and Content Panes, Panels, Mini panels, Panels everywhere, Page manager, Superfish for menus, Addthis, ...
30
votes
8answers
19k views

How to make a form required with states?

I have a drop down list that displays various fields based on what is chosen and I know that I can toogle the visibility with states but when I try to use required the * span is display but it isn't ...
6
votes
2answers
14k views

How to load a node edit form using Ctools module in Drupal 7

I am trying to load a node edit form into a modal frame using Ctools. The following is the function I am using. So far the $op = 'view' part is working fine, but I cannot get the node edit form to ...
3
votes
2answers
6k views

How do I properly pass values from PHP to JavaScript?

I am currently writing a module and I am trying to pass some variables to the Drupal.settings. My module uses the following code. function bcc_preprocess_views_view(&$vars) { drupal_add_js(...
2
votes
4answers
5k views

Change module's weight - by module or manualy

I am looking for solution how to change particular module's weight in D7. I know that it is possible to do in config tables in database, but I don't know how. Another solution that I found in Drupal....
27
votes
7answers
48k views

How to programmatically trigger a click on an AJAX enabled form submit button?

I'm trying to programmatically (with jQuery) trigger a click on button with AJAX behavior in a Drupal form, but so far jQuery('#edit-submit').click() doesn't do anything. A real mouse click on that ...
10
votes
5answers
18k views

hook_preprocess_page(): how to tell a views page?

Im writing a custom module that need to insert some javascript and css files only in a Views page. Im using hook_preprocess_page, but I can not tell if the current page is from a view: function ...
9
votes
4answers
19k views

How to make form buttons call only javascript?

I'm experimenting with JavaScript and Drupal forms. Currently I'm trying to make a button in the administration form of a module that will use JavaScript to append options to a select list. The ...
13
votes
5answers
9k views

How to prevent behavior-attached functions from being attached twice?

I have a behavior that adds on to some checkboxes. (function($) { Drupal.behaviors.mymodule = { attach: function (context, settings) { $('.skip-line', context).on('change', function(){ ...
6
votes
2answers
13k views

How to add CSS and JS files on node pages from theme's template.php

I am trying to add JavaScript and CSS files to one node type page from my template.php file but it is not working. Here is my template.php code: <?php // $Id: template.php,v 1.13 2010/12/14 01:...
7
votes
4answers
4k views

Sending a value to JavaScript

I have set theme handler for a form in Drupal and this handler has a template file. What is the easiest way to send a value from PHP to JavaScript in that include file?
3
votes
2answers
5k views

How to override Drupal.ajax.prototype.beforeSend?

I need to add my own little if's and checks in 3 functions inside misc/ajax.js ( Drupal.ajax.prototype.beforeSend, Drupal.ajax.prototype.success, Drupal.ajax.prototype.error ) How can I ...
2
votes
2answers
2k views

how to add javascript with #attached and hook_page_alter

I tried to add js to pages by means of #attached, as it seems to be the recommended way. From what I understand, this involves altering a render array. hook_page_alter seems to me like good candidate. ...
29
votes
5answers
24k views

How do I add JavaScript specific for a view?

I have a view in my site that has a specific class name. I want to know, inside the template.php file of a theme, how I can know if a view with specific class name is available in the requested page. ...
17
votes
5answers
14k views

Add JavaScript files to the administrative pages

How do I add JavaScript/CSS files in every administration pages, using a module?
19
votes
4answers
8k views

Easiest method for conditional fields in a form

What is the easiest way to get some javascript magic for enabling/disabling form fields based on another field's value? This sounds like something there should be an helper for somewhere, but I can't ...
12
votes
1answer
9k views

How do I use a jQuery version different from the default one used by core?

I need to use a different jQuery version. Currently, Drupal is using jQuery 3.2.1, but I need a previous version. In Drupal 7 you could easily change jQuery version with the jQuery Update module. How ...
1
vote
1answer
5k views

how to set and unset javascript files for specifc path aliases in Drupal 7?

I am trying to set particular javascript files for a specific node page by getting the path alias. like this: $path=drupal_get_path_alias(); if($path == 'about-us') drupal_add_js(drupal_get_path('...
8
votes
4answers
7k views

Delay ajax call on textfield to allow for typing

I would like to delay ajax from firing in the same way that the autocomplete seems to work. For example, if a user it typing, the ajax will not run until 500ms has elapsed since the last keyup. I am ...
7
votes
7answers
16k views

How can I trigger a javascript function when a Drupal ajax call is complete?

I need to do some extra things after Drupal ajax is done inserting some stuff into the DOM. With jQuery this was brain-dead simple, but I can't for the life of me figure out how to do it in Drupal 7 :...
3
votes
1answer
2k views

Multiple nodes in one slide using views slideshow or another module

I have a slideshow using views_slideshow which displays the latest post from 4 different content types, I need the slide to show multiple contents (from different content types) in one slide, when you ...
6
votes
2answers
6k views

How to extend or “hook” Drupal Form AJAX?

I'm working with standard admin form, which has 'add_more' button for one of fields. My task is to move some fields to jQuery UI Dialog just for usability. When dialog was closed I manually append it'...
2
votes
3answers
2k views

Using custom JavaScript

Is there a location where I can drop in a custom JavaScript file in Drupal 7.x? It just includes simple event actions for menus, and I don't want to edit the theme/module files. Or do I have to just ...
8
votes
1answer
13k views

Pass variable to drupalSettings

I'm using Drupal 8. What I'm trying to do is: Access the active node From the node get the value of field_test and assign it to a variable Pass the variable to the drupalSettings function and ...
4
votes
1answer
2k views

Add inline JavaScript to end of page dynamically

Use case: I have a custom block: /** * Provides a 'Hello' Block * * @Block( * id = "my", * admin_label = @Translation("My Block"), * ) */ class MyBlock extends BlockBase { /** * {@...
3
votes
2answers
3k views

Changing file name on upload

I'm trying to automatically add prefixes to uploaded file names so they can later be processed by non-drupal scripts. I want to do that while the user is uploading files during creation/editing of a ...
2
votes
1answer
4k views

jquery script on view not working when filtering with (ajax on) 'better_exposed_filters' module

i have a script for dealing with node images hover (function ($) { $(function(){ $('.node-photos-teaser').mouseenter(function() { $(this).addClass('photos-hover'); }).mouseleave(...
2
votes
3answers
5k views

How to add default text that clears on focus with jQuery to a search form text field in Drupal

I would like to have a default text in an Exposed Views Search form that says something like 'type in a keyword to search' which will disappear if the user clicks on the text field and reappear if the ...
1
vote
1answer
1k views

Remove jQuery and find out what is asking it to be included

I'm using drupal 7 and I simply don't want jQuery included at all. It seems like most people are advocating modify the js in a theme hook. That's fine I suppose, but it seems like this is dangerous ...
3
votes
3answers
4k views

$ is not a function in drupal 7 theme

$(function(){ $('.slider').mobilyslider({ content: '.sliderContent', children: 'div', transition: 'horizontal', animationSpeed: 500, autoplay: true, autoplaySpeed: 9000, ...
2
votes
2answers
8k views

How can I remove Javascript files?

I wanted to remove some JavaScript files, since they conflict with my custom JavaScript on my mobile theme. I tried with the following code, but it is not working in hook_preprocess_page(), which I ...
1
vote
1answer
4k views

EntityMalformedException: Missing bundle property on entity of type node in modal

I want to open create content type in modal, according to modal form and modal api example, I implement it, I test the problem is here when I test it by contact form ctools_include('modal'); ...
1
vote
1answer
646 views

Popup module is not working in custom front page [closed]

I am using the Popup module. I want to display a particular block content in popup. So I used this module. it's working good except in my custom front page (page--front.tpl.php).I don't know why. My ...
34
votes
4answers
17k views

How do I change the ajax loading behaviour in Views?

I have a view with some exposed filters in a block; it uses AJAX and the auto-submit feature so the view is re-loaded as soon as a filter option is changed. In the short delay between selecting an ...
19
votes
12answers
29k views

How to add Jquery plugin to Drupal?

Should I just paste the code in the main template file, or is there any other recommended way of attaching new Jquery plugins in Drupal 7?
13
votes
2answers
17k views

How can I return actual JSON using Drupal?

I'd like to implement a simple AJAX function locally that allows me to autocomplete node titles of already existing nodes as the user types. To that end, I need the ability to have an API that I can ...
9
votes
3answers
11k views

How do I add CSS & JavaScript to <head>?

I want to add the following code in my section of the front page using a Drupal 8 sub theme of Bartik. Can anybody help how to do it? What is the best way to do it in this new twig version of theme?...
12
votes
2answers
10k views

load a node content into a lightbox2 (without headers and footer and other blocks)

is it possible to load a node (from an id) into a lightbox 2 without having to load all the additional blocks ? just what the node has to display I want to make some popups on some links to allow ...
10
votes
5answers
12k views

How to add conditional javascript to theme?

I'd like to use Selectivizr script to emulate CSS3 selectors in IE6-8. But I'm having a hard time adding it to my theme. So far tried: 1) Forcing this into html.tpl.php head section: <!--[if lt ...
3
votes
1answer
2k views

Ctools modals without AJAX

What's the sanest way to present a Ctools modal to the user while bypassing the normal AJAX workflow? For example, how could I show a completely JavaScript-generated "Are you sure you want to log out?"...
10
votes
4answers
16k views

How to create modal windows (pop-ups)?

I am trying to use Drupal 8's core function to open a page in a modal window. Unfortunately it is very hard to find some official documentation about it, and most of the blogs covering this topic seem ...
8
votes
5answers
10k views

Adding JS to a Drupal 8 theme (replacement for drupal_add_js)

In Drupal 7, I can use drupal_add_js within a theme's template.php file as a theme_preprocess_html(&$vars) function: drupal_add_js(drupal_get_path('theme', 'mytheme') . '/js/scripts.js', ...
5
votes
2answers
13k views

How to display a node in overlay popup effect?

I have a content type 'students' with fields name, description and a photo. I have created a view(Block) to display only the images of the students. When the teacher/user clicks the photo of the ...
7
votes
3answers
11k views

How to pass PHP variables to Javascript/jQuery? [duplicate]

I found this way to send variables from PHP to Javascript. Inside the template.tpl.php file, I have the following code. <?php echo '<div class="drupal-vars" style="display:none;">'....
7
votes
2answers
18k views

How do I pass variables to JavaScript?

In your MODULENAME.module file: $testVariable = 'himanshu'; drupal_add_js(array('MODULENAME' => array('testvar' => $testVariable)), array('type' => 'setting')); drupal_add_js(drupal_get_path('...
5
votes
1answer
12k views

Drupal 7 - How to get AJAX response displayed in a ctools modal?

I want to create a ctools modal popup when a button is pressed. function custom_form( $form, &form_state ) { $form['btn'] = array( '#type' => 'button', '#value' => t('add'), '#...

1
2 3 4 5