2

Here is script

$('#first').change(function(){

    switch ($(this).val())
    {
        case '1st':
            $('.1st').show();
            $('.2nd').hide();
            break;

        case '2nd':
            $('.1st').hide();
            $('.2nd').show();
            break;

        case '3rd':
            $('.3rd').hide();
            $('.3rd').show();
            break;

        case 'none':
            $('.1st').show();
            $('.2nd').show();
            break;
    }
});

http://jsfiddle.net/8ZVSu/3/

In first Dropdown, All, Edit, Delete, Modify is given. I need like this..

  1. If I click All in first dropdown, it should display All,051,052,111,123,222,444,555,777,888,911,999 in second dropdown.

  2. If I click Edit in first dropdown, it should display All,051,052,111,123,222,444,555,777,888,911,999 in second dropdown.

  3. If I click Delete in first dropdown, it should display only All in second dropdown.

  4. If I click Modify in first dropdown, it should display only All in second dropdown.

I am having few doubts here.

2
  • Is it possible in jquery? you already used jquery Commented Jun 17, 2014 at 7:05
  • Yes used jquery only. But couldnt able to get the right one. Could you please help me with the code?> Commented Jun 17, 2014 at 7:06

3 Answers 3

2

Try this :

$('#first').change(function(){
    $('#second option').hide(); // hide all options
    switch ($(this).val())
    {
        case '1st':
            $('.1st').show();
            break;

        case '2nd':
            $('.2nd').show();
            break;

        case '3rd':
            $('.3rd').show();
            break;

        case 'none':
           // show all options except for delete and modify
           $('#second option').not('.3rd, .2nd').show();
            break;
    }
});

Working JSFiddle

Sign up to request clarification or add additional context in comments.

9 Comments

There is one problem here. If I click All in first dropdown, it is displaying All three times ..Can you please take a look?
This is because you have two more 'ALL' option at the bottom for class 2nd and 3rd. <option class="2nd" value="val13">All</option> <option class="3rd" value="val14">All</option>
That was given for Delete and Modify in first dropdown..But getting three All options in first dropdown!
And if you don't wan to repeat 'ALL' for Delete and modify then use only one 'ALL' option and make it hide and show.
Ok, in that case you have to omit these two 'ALL'. see here jsfiddle.net/8ZVSu/7
|
1

Demo In your context your first drop down value ,second drop down class has relation b/w each other .so using this.valueto get selected element

$('#first').change(function () {

    if (this.value == "none") {
        $("#second option").not(".2nd,.3rd").show();
    } else {
        $("#second option").hide();
        $("." + this.value).show();
    }


});

3 Comments

There is one problem here. If I click All in first dropdown, it is displaying All three times ..Can you please take a look?
same problem remains balachandran :(
@user3107196. actualy i did'not understand what you were asked . now i updated my post pls check it
0

Two way:

  1. you need 4 second select, show one of them when you change the first dropdown.

  2. use js template generate the second dropdown dynamic.

You can't show or hide <option> direct in chrome.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.