1

I'm trying to change a dropdown select menu with jqquery by selecting a certain option from a dropdown menu.

Example:

<select name="options">
    <option value='3'>Option 3</option>
    <option value='5'>Option 4</option>
    <option value='7'>Option 5</option>
</select>

The other dropdown:

<select name="rounds">
    <option value='1'>1</option>
    <option value='3'>3</option>
    <option value='5'>5</option>
    <option value='7'>7</option>
</select>

Say someone selects option 4, then the other dropdown will dynamicly change its values to say:

<select class='button' name="rounds">
    <option value='23'>23</option>
    <option value='5'>5</option>
    <option value='12'>12</option>
</select>

Each option will change the rounds menu and users can toggle between options. Anyway to do this? is there a demo online?

2 Answers 2

2

on Change when you need to remove all otpins something as below

$("[name='options']").change(function() 
    { 
        val = $(this).val(); 
        $("[name='rounds'] >option").remove();

than in if conditon add items one by one as per you needs

var opt ;
if(val == 4)
{
  opt = {
        val1 : 'text1',
        val2 : 'text2'
    };
}
if(val ==1 )
{
          opt = {
        val1 : 'text3',
        val2 : 'text4'
    };
}
    $.each(opt, function(val, text) {
        $("[name='rounds']").append(
            $('<option></option>').val(val).html(text)
        );
    });

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

Comments

1

I hope this is what you are looking for checkout the link

http://api.jquery.com/val/#val

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.