Link to home
Start Free TrialLog in
Avatar of Heather Ritchey
Heather RitcheyFlag for United States of America

asked on

jQuery function not working

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

ASKER CERTIFIED SOLUTION
Avatar of wellhole
wellhole

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Heather Ritchey

ASKER

Ok, that worked. I tried adding it right after the fields assuming that would work. Thanks much!
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