Showing hiding a list when a checkbox is clicked?

C

Cheddar

I'm back again with another problem.

What I want is for the user to click a checkbox and have a
list appear. I think the code is almost there but it doesnt
seem to be working, grrrr. Can anyone help me out with it.

Also is there a initial way to hide a list when the page is
loaded?

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>

<script LANGUAGE="JavaScript">
function elemDisplayToggle (elemID) {
if ( document.getElementById( elemID ).style.display ==
'none' ) {
document.getElementById( elemID ).style.display =
'block';
}
else {
document.getElementById( elemID ).style.display =
'none';
}
}
</script>

<body>
<input type="checkbox" name="box1"
onclick="elemDisplayToggle(choices)" value="checkbox">
<select name="choices">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</body>
</html>

Thanks
 
G

Geoff Tucker

Cheddar said:
I'm back again with another problem.

What I want is for the user to click a checkbox and have a
list appear. I think the code is almost there but it doesnt
seem to be working, grrrr. Can anyone help me out with it.

Also is there a initial way to hide a list when the page is
loaded?

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>

<script LANGUAGE="JavaScript">
function elemDisplayToggle (elemID) {
if ( document.getElementById( elemID ).style.display ==
'none' ) {
document.getElementById( elemID ).style.display =
'block';
}
else {
document.getElementById( elemID ).style.display =
'none';
}
}
</script>

<body>
<input type="checkbox" name="box1"
onclick="elemDisplayToggle(choices)" value="checkbox">
<select name="choices">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</body>
</html>

Thanks

The function's parameter in your onclick event should be passed as a
string - onclick="elemDisplayToggle('choices')"

To initially hide the select element - <select name="choices"
style="display:none">

Hope this helps
Geoff
 
C

Cheddar

Geoff said:
parameter in your onclick event should be passed as a
string - onclick="elemDisplayToggle('choices')"

To initially hide the select element - <select name="choices"
style="display:none">

Hope this helps
Geoff

Thanks for the help Geoff, I got it to work but decided it
looked pretty awful, having lists just appear looks very
dodgy.

I have now decided to try to simply enable/disable a select
list on the click of a checkbox. I have got it to work but I
cannot get the list to reset. Ideally if a user clicks the
box and selects a option and then changes their mind and
clicks the checkbox to disable their choice then the list
should reset itself to it's standard value (option 1 in this
case).

Any ideas of how I would do this?

Thanks.

------------------------------------------------------------
------

<script language="JavaScript" type="text/javascript">
<!--
function toggleSelect (select) {
if (!select.disabled) {
select.disabled = true;
}
else {
select.disabled = false;
}
}
//-->
</script>
</head>
<body>

<input type="checkbox" name="box1"
onclick="toggleSelect(choices);">
<select id="choices" disabled="true">

<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
</body>
</html>
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
function toggleSelect (select) {
if (!select.disabled) {
select.disabled = true;
}
else {
select.disabled = false;
}
}

Naive.

function toggleSelect (select) { select.disabled = !select.disabled }
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top