Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listbox visible if certain value selected in another listbox 1

Status
Not open for further replies.

tamnet

IS-IT--Management
Jun 2, 2005
31
GB
I posted this in the asp forum but I was told this would be better posted here

I am trying to have a listbox either visible or invisible based on wether another listbox value contains the letter "d", I have tried to write the following function without success and wondered if someone would take a look and perhaps steer me in the right direction


Code:
<script language="javascript">
function ToggleListBoxDisplay(){
var lstFlute=document.getElementById("lstFlute")
if Right(lstFlute.value= "d")
  lstMiddle.visible = true;
else
lstMiddle.visible = false;
}
</script>

I then call the function like this


Code:
onChange="ToggleListBoxDisplay()"
Regards

Paul
 
[1] Name and id : do not start with numeric, it does not comply with w3c html standard. But most importantly, javascript variable cannot start with numeric. It would fail, period. Hence, change variable 1stFlute to say firstFlute. It is highly recommended to change as well the id accordingly. Similarly 1stMiddle.
[2] There are javascript syntax errors.
[3] There are dom error.
[4] Right() vbs function. Do you mean by the right-most character? The revision is based on this assumption.
You see every different kind of error.
[tt]
function ToggleListBoxDisplay(){
var firstFlute=document.getElementById("firstFlute");
var x=firstFlute.value;
if (x.substring(x.length-1,x.length)=="d"){
document.getElementById("firstMiddle").style.visibility="visible";
} else {
document.getElementById("firstMiddle").style.visibility="hidden";
}
}
[/tt]
 
tsuji,
Firstly thanks for your reply and also the comments, i am just starting out really so any help is appreciated. Just to let you know that the field ID 1stFlute should have been lstFlute(in Caps = LSTFLUTE), it must have got screwed up when i copied/pasted my question from the asp forum page to here

anyway thanks again and a "star" for you, it works great but i would like the field "firstmiddle" invisible when the page loads could you help me with this please ?

Regards
Paul
 
>field ID 1stFlute should have been lstFlute(in Caps = LSTFLUTE)
In that case no problem at all. I just look at the screen and do my revision. That's my mis-persception then.

>i would like the field "firstmiddle" invisible when the page loads...
To make it set hidden on loadtime, you can add the instruction to the onload handler. (I restore the lstMiddle.)
[tt]<body onload="document.getElementById('lstMiddle').style.visibility='hidden';">
[/tt]
 
tsuji,
Fantastic that works a treat

Thank You again


Regards

Paul
 
tsuji,
I just been given a change to what is required, it now seems that we need to say

if lstFlute.value = either "d" or "t" then make the field visible, I have tried a number of mods but because of my lack of experience cannot get it to work, below is what I have tried

Code:
<script language="javascript">
function ToggleListBoxDisplay(){
    var lstFlute=document.getElementById("lstFlute");
    var x=lstFlute.value;
    if (x.substring(x.length-1,x.length)=="d","t"){
        document.getElementById("lstMiddle").style.visibility="visible";
    } else {
        document.getElementById("lstMiddle").style.visibility="hidden";
    }
}

</script>

and this

Code:
<script language="javascript">
function ToggleListBoxDisplay(){
    var lstFlute=document.getElementById("lstFlute");
    var x=lstFlute.value;
    if (x.substring(x.length-1,x.length)=="d")or (x.substring(x.length-1,x.length)=="t"){
        document.getElementById("lstMiddle").style.visibility="visible";
    } else {
        document.getElementById("lstMiddle").style.visibility="hidden";
    }
}

</script>

any chance of some further help please


Regards

Paul
 
[tt]> var x=lstFlute.value;
> if (x.substring(x.length-1,x.length)=="d","t"){[/tt]
To shorten the look a bit.
[tt] var x=lstFlute.value;
var y=x.substring(x.length-1,x.length);
if ((y=="d")||(y=="t")){
[/tt]
 
tsuji,
cannot thank you enough, looks like i was on the right lines but not close enough


Regards

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top