Welcome Guest, Not a member yet? Register   Sign In
Hide Dropdowns from each other with if statement???
#1

[eluser]Nummero2[/eluser]
Hi,

i´ve got a create form which sents data to a mysql table. In this form I´ve got two dropdown menues.

Is it possible to make one of them invisible if a certain value is selected in the other one?

Example:

Dropdown 1 values: no value, one, two, three;
Dropdown 2 values: no value, 99, 88, 77;

So I want to achieve that when the user selects a value in Dropdown 1 like "one" the Dropdown 2 is hiding automatically or doesn´t allow an entry at least.

With Dropdown 2 vice versa.

Hoping for your great ideas as always :-)

Greetings Sebastian
#2

[eluser]xwero[/eluser]
That is simple code with jQuery
Code:
$('#dropdown1, #dropdown2').click(function(){ // catch click event for the two dropdowns
   var clicked = $(this).attr('id').replace(/dropdown/,''); // get number of dropdown
   var notclicked = (clicked == 1)?2:1; //
   $('#dropdown'+notclicked).attr('disabled',TRUE); // disable not clicked dropdown
});
It a little more complicated when you want to re-enable the dropdown when the no value option is choosen.
#3

[eluser]Nummero2[/eluser]
Thank you for your answer. My Problem is that I have different DOM Ids for my dropdowns.

Id Dropdown1: todo_id
Id Dropdown2: project_id (looked with firebug)

For todo_id it looks like this "inspected":
Code:
select id="todo_id" name="todo_id">
<option value="0">no task</option>
<option value="1">test todo one</option>
<option value="2">test todo two</option>
</select>

For project_id its the same with different values.

Now what I want is when a user selects a different entry from value="0" no task in any of the two dropdowns the other one should hide.

Here´s the code I tried:

Code:
$('#todo_id, #project_id').click(function(){ // catch click event for the two dropdowns
        var clicked = $(this).attr('id').replace(/dropdown/,''); // get number of dropdown
        var notclicked = (clicked == todo_id)?project_id:todo_id; //
        $('#notclicked').attr('disabled',TRUE); // disable not clicked dropdown
        });

Doesn´t work :-(
#4

[eluser]Nummero2[/eluser]
friendly push :-)
#5

[eluser]Randy Casburn[/eluser]
disclaimer - I don't know jQuery all that well.
Code:
$('#todo_id, #project_id').click(function(){ // catch click event for the two dropdowns
   var clicked = $(this).attr('id').replace(/dropdown/,''); // get number of dropdown
   var notclicked = (clicked == 1)?'#project_id':'#todo_id'; //  <<<--- CHANGE
   $(notclicked).attr('disabled',TRUE); // disable not clicked dropdown
});

Try?

[edit] I change the dropdown DOM ids so they are correct now.




Theme © iAndrew 2016 - Forum software by © MyBB