Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more

Questions tagged [javascript]

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

Filter by
Sorted by
Tagged with
34 votes
4 answers
50k 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)?
Karmacoma's user avatar
  • 1,043
59 votes
2 answers
46k 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', ...
Hacker's user avatar
  • 3,024
42 votes
3 answers
50k 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 ...
Alexey's user avatar
  • 941
9 votes
2 answers
21k views

How do I add JavaScript to a site?

How can I add JavaScript and CSS to my site?
kinkajou's user avatar
  • 223
31 votes
2 answers
36k 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, ...
EB84's user avatar
  • 1,417
6 votes
2 answers
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 ...
Benjen's user avatar
  • 928
3 votes
2 answers
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(...
Jurudocs's user avatar
  • 702
2 votes
4 answers
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....
Benas Plentas's user avatar
29 votes
7 answers
54k 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 ...
Daniel's user avatar
  • 1,245
16 votes
5 answers
11k 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(){ ...
Mołot's user avatar
  • 21.9k
12 votes
1 answer
13k views

How to Trigger Existing, Non-Form Ajax from JavaScript Event

I'm trying to figure out AJAX in Drupal 8. I have a custom module that works, using AJAX to change the content of a div when a link is clicked. The API says: Many different events can trigger ...
user70961's user avatar
  • 145
11 votes
5 answers
24k 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 ...
Strae's user avatar
  • 890
10 votes
4 answers
21k 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 ...
Sathariel's user avatar
  • 679
7 votes
4 answers
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?
farzan's user avatar
  • 417
3 votes
2 answers
7k 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 ...
Mołot's user avatar
  • 21.9k
2 votes
2 answers
3k 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. ...
Dalmaz's user avatar
  • 510
29 votes
5 answers
27k 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. ...
Mehrdad201's user avatar
  • 1,312
19 votes
4 answers
9k 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 ...
Fuzzy76's user avatar
  • 578
17 votes
5 answers
16k views

Add JavaScript files to the administrative pages

How do I add JavaScript/CSS files in every administration pages, using a module?
Onita's user avatar
  • 714
12 votes
1 answer
34k 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 ...
lane's user avatar
  • 473
12 votes
2 answers
14k 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 ...
dekisha's user avatar
  • 133
11 votes
4 answers
21k 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 ...
user5950's user avatar
  • 2,048
10 votes
1 answer
4k views

How can I force a JavaScript library to load in the <head> of a page?

How do I force a JavaScript library to load in the < head > in Drupal 8? Here's my themename.libraries.yml file: zaccordion: version: 1.x js: js/jquery.zaccordion.js: { header: true } ...
Sage's user avatar
  • 2,463
9 votes
5 answers
8k 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 ...
Inigo Montoya's user avatar
7 votes
7 answers
21k 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 :...
SomethingOn's user avatar
  • 1,281
6 votes
2 answers
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:...
zach's user avatar
  • 161
6 votes
2 answers
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'...
kalabro's user avatar
  • 7,949
5 votes
2 answers
19k views

How do I correctly use jQuery once()?

Due to a module, the Drupal behavior I implemented is called five times instead of once. (function ($) { Drupal.behaviors.myFunction = { attach: function (context, settings) { // … } ...
maen's user avatar
  • 460
5 votes
1 answer
3k 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 { /** * {@...
Tobias Krause's user avatar
3 votes
2 answers
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 ...
Pawel G's user avatar
  • 513
3 votes
1 answer
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 ...
Ashkar A.Rahman's user avatar
2 votes
3 answers
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 ...
Adam S's user avatar
  • 5,031
2 votes
1 answer
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('...
paranod's user avatar
  • 365
2 votes
1 answer
5k 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(...
Matoeil's user avatar
  • 3,425
2 votes
3 answers
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 ...
Anthony Miller's user avatar
2 votes
2 answers
9k 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 ...
ninjascorner's user avatar
  • 1,841
1 vote
1 answer
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'); ...
Yuseferi's user avatar
  • 22k
1 vote
1 answer
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 ...
gregghz's user avatar
  • 767
35 votes
4 answers
19k 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 ...
Clive's user avatar
  • 167k
19 votes
12 answers
30k 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?
Vonder's user avatar
  • 713
14 votes
4 answers
29k views

How to load content in a div with ajax?

After validate with javascript that I'll be able to use the client location: if (navigator.geolocation) { ... I need to load the content of a view block with arguments (based in the position coords)....
Adrian Cid Almaguer's user avatar
13 votes
2 answers
20k 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 ...
rybosome's user avatar
  • 941
12 votes
2 answers
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 ...
PartySoft's user avatar
  • 1,036
10 votes
3 answers
14k 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?...
Manu Adam's user avatar
  • 101
10 votes
5 answers
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 ...
pushka's user avatar
  • 1,853
10 votes
3 answers
29k 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('...
harshal's user avatar
  • 4,364
9 votes
5 answers
32k views

What's the event triggered after an autocomplete has run and how to retrieve the value selected

I have a node add form with a term reference that uses autocomplete widget. I want the "tid" of the filled term by the user using the autocomplete widget.
sel_space's user avatar
  • 1,134
8 votes
5 answers
13k 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', ...
Danny Englander's user avatar
7 votes
3 answers
12k 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;">'....
Xavi Colomer's user avatar
6 votes
3 answers
7k views

Use drupal #states to check a radio

I would like to translate some jquery .change functionality to use #states in the form api. var radio1 = jQuery('input:radio[name=radio_1]'); var radio2 = jQuery('input:radio[name=radio_2]'); ...
mikeytown2's user avatar
  • 8,332

1
2 3 4 5 6