Solved

jQuery function not working

Posted on 2011-02-14
3
330 Views
Last Modified: 2012-05-11
I'm terrible with jQuery. This is suppose to show the input box only when Other is selected from the dropdown, but it's not calling the function at all. Can someone give me a hand? FF isn't showing any errors either.

script:
$(".spacingbows").change(function(){
	alert('function called');
//set the select value
var val = $(this).val();
if(val != "Other") {
	$(this).nextAll('.spacingbowsother').hide();
} else {
	$(this).nextAll('.spacingbowsother').show();
}
})

Open in new window


Fields:
    <td width="198"><select size="1" id="R-4_h" class="spacingbows" name="R-4.h-Spacing-Between-Bows">
	<option<?php echo $x4h1;?> value="">Select one:</option>
	<option<?php echo $x4h2;?> value="4'">4'</option>
	<option<?php echo $x4h3;?> value="5'">5'</option>
	<option<?php echo $x4h4;?> value="6'">6'</option>
	<option<?php echo $x4h5;?> value="Other">Other</option>
</select> <input type="text" id="R-4_o" class="spacingbowsother" name="R-4.o-Spacing-Between-Bows-Other" size="20" value="<?php echo $_POST['R-4_o-Spacing-Between-Bows-Other'];?>" /> on center <span class="R">*</span></td>

Open in new window

0
Comment
Question by:Dzynit
3 Comments
 
LVL 9

Accepted Solution

by:
wellhole earned 500 total points
ID: 34889147
Did you run the script after the body was loaded?
0
 
LVL 14

Author Closing Comment

by:Dzynit
ID: 34889241
Ok, that worked. I tried adding it right after the fields assuming that would work. Thanks much!
0
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 34889301
you won't see an error because the code is valid. What wellhole is saying is that you need to make sure your script does not run until the page has completely loaded.

try the code below. If you are running into the same problem still, please post your entire script-block


$(document).ready(function() {
 $(".spacingbows").change(function(){
	alert('function called');
 //set the select value
 var val = $(this).val();
 if(val != "Other") {
 	$(this).nextAll('.spacingbowsother').hide();
 } else {
 	$(this).nextAll('.spacingbowsother').show();
 }
 });
});

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

757 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

23 Experts available now in Live!

Get 1:1 Help Now