开发者

jQuery Show items based on form selection

Hey there, I have a simple problem but can't seem to get the solution working. Basically I have a select. Depending on the option selection of this select it should display a separate corresponding select.

I have a js fidd开发者_如何学Pythonle going here: http://jsfiddle.net/FcsBu/22/

any help would be appreciated. thanks!


Your last selector is wrong

it should be either

$("#"+ optionValue).show('fast');

or

$("."+ optionValue).show('fast');

depending on whether the optionValue contains the class of the select you want to show or the id of the select you want to show.

Hope this helps! If it answered your question please click the checkbox next to my answer to accept it!


var optionValue = $ (this).val();
    $('#'+optionValue).show('fast');


You are using the wrong selectors

A working js fiddle is here

I made two changes first change the .selector to #selector because you are using id not class. second you have to use a selector for the show as well so I added the # ID selector to that and concatenated with the + to your variable which should not be in quotes

http://jsfiddle.net/Psvab/1/


I think you probably would want to hide the other options if you change selection.

$(document).ready(function() {
$('.coursedate').hide();
$('.course_type').change(function() {
    var optionValue = $(this).attr('value');
    $('.coursedate').hide(); // Add this to hide other options
    $('#'+optionValue).show('fast');
}); 

});


Fixed:

http://jsfiddle.net/FcsBu/30/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜