Solved

jQuery function not working

Posted on 2011-02-14
3
331 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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 …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

20 Experts available now in Live!

Get 1:1 Help Now