3 Replies - 2379 Views - Last Post: 04 December 2011 - 03:49 PM

#1 carlbrooks   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 19-November 11

buttons do not refresh when options in drop down menu changes

Posted 04 December 2011 - 05:36 AM

I have a two dropdown menus, the second drop down menu appears depending on what is selected in the first dropdown menu. Problem is that in some browsers, if something is selected in the first dropdown menu, then if I click on the second dropdown menu then a dropdown does not occur, but if I select something in the first dropdown menu again and then click on the second dropdown menu, then the dropdown appears in the second dropdown menu. Why is this happening?

In Internet Explorer, Firefox and Safari, my second drop down menu appears straight away when I click on it after selecting something on the first dropdown menu for the first time.

In google chrome and opera, I have to select options from the first dropdown menu twice to be able to get the second dropdown menu working.

The jquery code for the second dropdown menu is below:

$("#optiondropId").change(function(){
	
var OptDrop = new Array();
         
OptDrop.abc = ["",1,2];
OptDrop.abcd = ["",1,2,3];
OptDrop.abcde = ["",1,2,3,4];
OptDrop.trueorfalse = [1];
OptDrop.yesorno = [1];

var selectedValue = $(this).val();

    $("#numberDropId").html("");
    $.each(OptDrop[selectedValue], function(x,y){
        $("#numberDropId").append($("<option></option>").attr("value", y).html(y));
    });
    
});


The full code is in Jsfiddle. (the full code might not work fully in JSfiddle but it works in browsers on its own file and the full code shows the order of my code.


[1]: http://jsfiddle.net/XZ7um/2/

Is This A Good Question/Topic? 0
  • +

Replies To: buttons do not refresh when options in drop down menu changes

#2 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: buttons do not refresh when options in drop down menu changes

Posted 04 December 2011 - 05:39 AM

Moved to jQuery
Was This Post Helpful? 0
  • +
  • -

#3 carlbrooks   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 19-November 11

Re: buttons do not refresh when options in drop down menu changes

Posted 04 December 2011 - 03:41 PM

This is hopefully my last jquery question. I have a slight issue with my buttons and dropdown menu. What happens is lets say user chooses option type "ABCDE" in first dropdown menu and then second dropdown menu chooses the value "4" for the number of answers and then clicks on the buttons "A","B","C" and "E", well if the user then decides to change the option type to "ABC", the buttons "A", "B" and "C" are still selected from the last time they have been selected.

What I want is that if the Option Type (OptiondropId) changes, then buttons selected is refreshed so no buttons are selected from the last time they have been selected.

This did used to work but when I included my change() event handler in my code which I need, the buttons do not refresh whenever a new dropdown option (OptiondropId) is selected. So I think the edit of the code may need to happen in the code below:

             $(document).ready(function ()
        {
            var OptDrop = new Array();
    
    OptDrop.abc = ["",1,2];
    OptDrop.abcd = ["",1,2,3];
    OptDrop.abcde = ["",1,2,3,4];
    OptDrop.trueorfalse = [1];
    OptDrop.yesorno = [1];
            
            $("#optiondropId").change(function ()
            {
                var selectedValue = $(this).val();
                $("#numberDropId").html("");
                $.each(OptDrop[selectedValue], function (x, y)
                {
                    $("#numberDropId").append($("<option></option>").attr("value", y).html(y));
                });
            }); 
    
            $("#optiondropId").change();
        });  


My code is in JSfiddle, (the second dropdown menu and buttons may not appear in JSFiddle but the code does work properly, I feel it is better displaying code in JSfiddle then in my questions as it will take up a lot of space. If you want to see working version then post code in your web document and it should work).

My Code: [click below][1]


[1]: http://jsfiddle.net/XZ7um/10/
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4217
  • View blog
  • Posts: 13,330
  • Joined: 08-June 10

Re: buttons do not refresh when options in drop down menu changes

Posted 04 December 2011 - 03:49 PM

maybe it helps to set the display property back to "inline"
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1