Javascript

Programming in Javascript

What is the use of preventDefault() Method in jQuery

March 09, 2015 - 13:20

The preventDefault() method is used to stop any element form behaving its default behaviour. For example, if we have a hyperlink linked to a particular location. Using preventDefault() function we can restrict it from navigating to it the by a custom location in our javascript. You can use the method isDefaultPrevented to know whether this method was ever called (on that event object).

[Drupal] How to pass values from PHP to javascript in a Drupal site?

May 30, 2013 - 17:08

Are you looking for a way manipulate dom elements using javascript based on some values from PHP, then this article is for you. We had recently worked in a Drupal 6 site having the same scenario. Our requirement was to enable some checkboxes using javascript based on the values of some variables available in the backend, This was accomplished using Drupal.settings

How to edit JavaScript code in your browser and see the changes in real time?

May 16, 2013 - 16:31

Did you face a situation where you wished that you could edit JavaScript live on browser to make experimental changes in your code? Have your ever made modifications in JavaScript code without rewriting the file and reloading the web page see the changes in real time. Read on to know how to edit edit JavaScript code in your browser and see the changes in real time?

[Drupal] How to limit a text field to accept only numbers as input?

When developing a website we might often come across situations where we have to limit the entry into each text fields to a certain type. One of the common scenarios we run into when developing Drupal websites is to limit text fields to accept only numbers as its input. If you want to know how to limit a text field to accept only numbers as input then read on to find out more.

How to bind Lightbox popups to images loaded via AJAX

AJAX is now widely used in web development to make the user interfaces simpler and faster. We may use AJAX to load images after page load in order to increase performance. However if you want to have a lightbox popup with the full image bound to an image loaded by AJAX then you might run into problems. You will find that even after linking the JS, CSS files and adding the rel="lightbox" attribute to the images it might not work.

[Drupal] How to add Javascript validation to a checkbox to a Drupal form?

Suppose you have a checkbox in a Drupal webform that needs to be validated before submitting the form. You may be familiar with Drupal form validation but you can add validation using Javascript too. If you have a Drupal form in your Drupal website and want to know how to add Javascript validation to a checkbox to a Drupal form then read on

[Drupal] How to change the order of a slideshow on every pageload?

January 04, 2013 - 11:43

A large number of websites on the web today have some kind of slideshow in them and they are probably using a library like jQuery to create the slide effect. When there are 10 images cycling in a slideshow, you might want to shuffle the order of the slideshow a bit. If you have a slideshow in your Drupal website and want to know how to change the order of the slideshow on every pageload then continue reading to know more.

[SOLVED][Drupal] Quicktab cookie is not persisting after closing and re-opening browser.

On one of the Drupal projects we had recently worked on, the client wanted us track the last active tab. We had used the Drupal Quicktab module to create the tabs. However we noticed that the quicktab cookie used to track the last active tab is not persisting after closing and reopening the browser. If you are facing the same scenario in your Drupal site and want to know the solution then continue reading.

[Drupal 7] How to create a simple Javscript popup without using third party Javascript libraries?

We had come across many situations while developing Drupal based websites where we had to create Javascript popups without using third party Javascript libraries. Third party libraries often lead to dependency issues or conflicts with existing Javascript functionalities. If you want to know how to create a simple Javscript popup in your Drupal website without using third party Javascript libraries then continue reading.

Drupal Tips - How to theme the File Upload field in a WebForm using CSS and JavaScript?

The trick explained briefly

We are not actually going to theme the file upload field as it is presently nearly impossible to do that. Instead we are going to put an ordinary looking 'dummy' input text field over the file field. Next we proceed to make the 'original' file upload field invisible but accessible to the user via CSS. So when a user clicks on the dummy input text field they are actually clicking on the file upload field itself. To make it authentic we are going to copy the file path from the file upload field to the text input field via javascript.

[SOLVED] JavaScript Error in IE8 - Webpage error details "Message: Invalid argument."

We were testing our newly implemented modal popup for a login functionality. It was working pretty good in Firefox, Opera, and Chrome but not in IE8. When attempts to login by clicking on a login link the login modal was not appearing in IE8. Firebug said nothing, but jquery-1.7.2.min.js in IE showed the following error:

Pages