473,432 Members | 1,664 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,432 software developers and data experts.

Showing hiding a list when a checkbox is clicked?

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
Jul 23 '05 #1
3 1907

"Cheddar" <my*************@dsl.pipex.com> wrote in message
news:c5************@ID-179732.news.uni-berlin.de...
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


Jul 23 '05 #2
Geoff Tucker wrote:
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>
Jul 23 '05 #3
JRS: In article <c5************@ID-179732.news.uni-berlin.de>, seen in
news:comp.lang.javascript, Cheddar <my*************@dsl.pipex.com>
posted at Thu, 15 Apr 2004 21:40:42 :
function toggleSelect (select) {
if (!select.disabled) {
select.disabled = true;
}
else {
select.disabled = false;
}
}


Naive.

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

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: luvdairish | last post by:
Can someone please look at my code and see why tables are not hiding properly? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD><TITLE>Untitled Document</TITLE> <META...
6
by: luvdairish | last post by:
I tried posting a few times, but it hasn't shown up. Hope this one works. Problem: Having trouble hiding tables when page is loaded. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0...
0
by: Steven | last post by:
Hi, I'm creating a custom checkbox list control which will take 2 arraylists as input. (One will contain Names and other will contain 0s and 1s. 0 - uncheck 1- check). I'm able to create the...
1
by: Amber | last post by:
The DataGrid allows you to make columns visible or invisible on demand - even edit and other special columns. This article will show you how it is done. Some developers have reported problems...
1
by: adam | last post by:
h How do i get an asp checkBoxList to emit client script. I want it so that when each checkbox is clicked, i can cause some action to happen i tried CheckBoxList cbl = new CheckBoxList()...
1
by: mschoup | last post by:
I have a simple aspx page(WebForm1.aspx) with a HyperLink, LinkButton, and two CheckBoxes. When I select a CheckBox and then click the LinkButton, the CheckBox retains state. When I select the...
9
daoxx
by: daoxx | last post by:
Hi Question#1 Is it possible to show a textbox (linked to a field) when the mouse pointer goes over a checkbox, and hiding it when the pointer goes away, and at the same time allowing the user to...
11
by: JeffP | last post by:
Just have a small problem with boolean fields in a list box showing as 0 and -1, not Yes/No or True/False. Is there any fix to this? -- Jeff "More Access Stuff." http://www.asken.com.au
2
by: uraliar | last post by:
Hello! What should I do to call a list box every time I clicked a checkbox? Thanks!
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.