javacsript problem

N

neetu

Hi

I hava a menu like this:

[+] personal
[+] income
[+] return
[+] filing

and the following javascipt:

var expand='on' ;

function switchid(id){
hideallids(ids);
if(expand=='on'){
showdiv(id);
expand='off';
}
else{
expand='on';
hidediv(id);
}
}

When user clicks on [+] of 'personal' the menu expands and when he
again clicks on it the menu collapses. if 'personal' is already in
expanded state and the user clicks on 'income' then also 'personal'
collapses. What i want is that 'personal' collapses but at the same
time 'income' should expand without disturbing the existing
functionality. pls tell me how to implement it.
 
D

Dmitry A. Soshnikov

Hi

I hava a menu like this:

[+] personal
[+] income
[+] return
[+] filing

and the following javascipt:

var expand='on' ;

function switchid(id){
š š hideallids(ids);
š š if(expand=='on'){
š š š š showdiv(id);
š š š š expand='off';
š š }
š š else{
š š š š expand='on';
š š š š hidediv(id);
š š }

}

if 'personal' is already in
expanded state and the user clicks on 'income' then also 'personal'
collapses.

sure, 'cause you collapse all the divs any time first - "hideallids
(ids);" independent of any state.

What i want is that 'personal' collapses but at the same
time 'income' should expand without disturbing the existing
functionality.

Do you want to handler collapsed/expanded state of just related
menuitem? Than, just set own state for every item. And when handling
event, see exactly that state and show/hide div depending on this
state.

hideallids(ids);
....
else{
expand='on';
hidediv(id);
}

this part makes no sense - you already hided all divs first.

Shortly, you need own state for every menuitem to solving you issue.
 
N

neetu

i cant set state for each menu item since i have a very long menu. can
there be any other solution except setting the states for each menu
item.

Secondly,this below code is required

else{
expand='on';
hidediv(id);
}

because initially all the ids are hidden but what i want is when i
click on personal it should expand and when i again click on personal
it should hide + what is required is when i click on second menu item
then also the first menu item should collpse and the second expanded

I hava a menu like this:
[+] personal
[+] income
[+] return
[+] filing
and the following javascipt:
var expand='on' ;
function switchid(id){
Å¡ Å¡ hideallids(ids);
Å¡ Å¡ if(expand=='on'){
Å¡ Å¡ Å¡ Å¡ showdiv(id);
Å¡ Å¡ Å¡ Å¡ expand='off';
Å¡ Å¡ }
Å¡ Å¡ else{
Å¡ Å¡ Å¡ Å¡ expand='on';
Å¡ Å¡ Å¡ Å¡ hidediv(id);
Å¡ Å¡ }

if 'personal' is already in
expanded state and the user clicks on 'income' then also 'personal'
collapses.

sure, 'cause you collapse all the divs any time first - "hideallids
(ids);" independent of any state.

What i want is that 'personal' collapses but at the same
time 'income' should expand without disturbing the existing
functionality.

Do you want to handler collapsed/expanded state of just related
menuitem? Than, just set own state for every item. And when handling
event, see exactly that state and show/hide div depending on this
state.

hideallids(ids);
...
else{
        expand='on';
        hidediv(id);
    }

this part makes no sense - you already hided all divs first.

Shortly, you need own state for every menuitem to solving you issue.
 
D

Dmitry A. Soshnikov

i cant set state for each menu item since i have a very long menu. can
there be any other solution except setting the states for each menu
item.

You anyway make actions by showing/hiding div, right? So use just
style-property (or better, what i recommend, css-class) to determinate
the state. The most useful solution in here - is just changing the
className of the div:

..CollapsedMenuItem {
display: none;
...
}

..ExpandedMenuItem {
display: block
...
}

and toggle function should analyze the value of className (that's the
state value u need) and change it.
but what i want is when i
click on personal it should expand and when i again click on personal
it should hide + what is required is when i click on second menu item
then also the first menu item should collpse and the second expanded

then hid all divs only when collapse action is, when expanding, don't
hide all divs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top