jQuery not working with Drupal 7 Webform fields.

Posted on 2013-05-13
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
LVL 13

Accepted Solution

Arrow_1 earned 166 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:
LVL 17

Assisted Solution

nanharbison earned 167 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 167 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Introduction HyperText Transfer Protocol ( or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now