jQuery not working with Drupal 7 Webform fields.

Posted on 2013-05-13
Medium Priority
Last Modified: 2013-05-15
Hello Experts,

I am trying to do a quick alert on the 'changing' of a textfield using jQuery in Drupal.  My theme .info files does have:
scripts[] = info.js

Open in new window

and the .js file is in the same dir as the .info file (for now)

The code in the .js file is:
$(document).ready(function() {
	$('#edit-submitted-num1').change(function() {
		alert('num1 changed!');

Open in new window

It's not giving me an alert.  Attahed is the simpel webform I created.

Sorta stuck on this simple code.

Question by:Modifier1000
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 13

Accepted Solution

Aaron Feledy earned 664 total points
ID: 39163202
With Drupal you usually need to use "jQuery" instead of "$" to avoid conflicts. Should look more like this:
jQuery(document).ready(function($) {
  $('#edit-submitted-num1').change(function() {
    alert('num1 changed!');

Open in new window

More here: http://drupal.org/node/171213
LVL 17

Assisted Solution

nanharbison earned 668 total points
ID: 39163363
Make sure you choose the text format as PHP code. If that is not a choice, go to the modules page and enable it.
LVL 16

Assisted Solution

HagayMandel earned 668 total points
ID: 39167136
Check whether the javascript is actually loaded. (look at 'page source').

Author Closing Comment

ID: 39169524
Got it to work!  
Actually the help from all of you was very helpful, thanks!

(function ($) {

	var content = '';

	 $('#edit-submitted-cat-1-reim-prior,#edit-submitted-cat-1-reim-curr,#edit-submitted-cat-1-reim-total').change(function() {
		 content1 = parseInt($('#edit-submitted-cat-1-reim-prior').val(), 10);
		 content2 = parseInt($('#edit-submitted-cat-1-reim-curr').val(), 10);
		 contentTotal = parseInt(content1 + content2);


Open in new window


Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question