Forum Moderators: open

Message Too Old, No Replies

Hiding/showing layers and general question

Javascript;layers

         

KristianN

1:28 pm on Mar 2, 2006 (gmt 0)

10+ Year Member



Hello.

I got a question regarding layers.
Let's say I got this:
<input type=radio name=test value=1 checked=1>1<input type=radio name=test value=0>2
2 buttons, one is called 1 and the other is called two.

When I push 1, I want "<SELECT NAME=LeFreq SIZE=6>" To dissapear.

Imagine a Disable/enable switch the disables/enables lights in your room.

How in the world do I do that? - I read something about layers and css, but I didn't understand much of it I'm afraid.

Would anyone be interested in perhaps elaborating it a bit further?

Nice page you got here by the way, registered today but often got very good hints and tips from here :)

prasanth jvrs

4:58 pm on Mar 2, 2006 (gmt 0)

10+ Year Member



Hi,

Hope this helps.

<html>
<head>
</head>
<body>
<form name="form1">

<input type=radio name=test value=1 checked onclick="disableHobbies()">1

<input type=radio name=test value=2 onclick="disableHobbies()">2

<select name="hobbies" style="display:none">
<option value="hob1">Hobbies 1
<option value="hob2">Hobbies 2
<option value="hob3">Hobbies 3
</select>

</form>
</body>
</html>
<script>

function disableHobbies() {
var testval=document.getElementById("test");

for(var i=0;i<testval.length;i++) {
var hobbiesval=testval(i).value;
if(hobbiesval==1) {
alert("came here");
document.getELementById("hobbies").display="block";
}
}
}

</script>

Thanks
Prasanth J.V.R.S

prasanth jvrs

5:04 pm on Mar 2, 2006 (gmt 0)

10+ Year Member



Hi,

Sorry please look into this code...

<html>
<head>
</head>
<body>
<form name="form1">

<input type=radio name=test value=1 onclick="disableHobbies()">1

<input type=radio name=test value=2 checked onclick="disableHobbies()">2

<select id="hobbies" name="hobbies" style="display:none">
<option value="hob1">Hobbies 1
<option value="hob2">Hobbies 2
<option value="hob3">Hobbies 3
</select>

</form>
</body>
</html>
<script>

function disableHobbies() {
var testval=document.forms[0].test;

for(var i=0;i<testval.length;i++) {
var hobbiesval=testval[i].value;
if(testval[0].checked) {
document.getElementById("hobbies").style.display="block";
}
else {
document.getElementById("hobbies").style.display="none";
}
}
}

</script>

Thanks
Prasanth J.V.R.S

KristianN

6:45 am on Mar 3, 2006 (gmt 0)

10+ Year Member



Thank you!

It doesn't seem as it should to me, but at least it has given me some inspiration to work with :)

Bernard Marx

8:50 am on Mar 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes. I'm not sure what the loop is for there.


function disableHobbies() {
var display = document.forms[0].test[0].checked? "none":"";
document.getElementById("hobbies").style.display = display;
}

KristianN

9:51 am on Mar 6, 2006 (gmt 0)

10+ Year Member



This is how I did it:

I added a script in the header:

<head>
<script>

function ToggleVisibility(el)
{
if( document.getElementById(el).style.visibility!= 'hidden' )
document.getElementById(el).style.visibility = 'hidden';
else
document.getElementById(el).style.visibility = 'visible';

}

function HideVisibility(el)
{
document.getElementById(el).style.visibility = 'hidden';
}

function ShowVisibility(el)
{
document.getElementById(el).style.visibility = 'visible';
}
</script>
</head>

Then I did:

<% If Request.QueryString("Leakdet0") = "0" Then %>

<td><b><INPUT onclick=HideVisibility('LeakageOptions') TYPE=RADIO NAME=LeakDet0 VALUE=0 checked>Disabled <INPUT onclick=ShowVisibility('LeakageOptions') TYPE=RADIO NAME=Leakdet0 VALUE=1>Enabled </b></td></tr>

<% Else %>

<td><b><INPUT onclick=HideVisibility('LeakageOptions') TYPE=RADIO NAME=LeakDet0 VALUE=0>Disabled <INPUT onclick=ShowVisibility('LeakageOptions') TYPE=RADIO NAME=Leakdet0 VALUE=1 checked>Enabled </b></td></tr>

<% End If %>

Where <div id='leakageoptions'> pointed to a table which had the options for disable enable. And it worked out great :)