Solved

jQuery function not working

Posted on 2011-02-14
3
336 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
[X]
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
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

724 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