473,785 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>

<script LANGUAGE="JavaS cript">
function elemDisplayTogg le (elemID) {
if ( document.getEle mentById( elemID ).style.display ==
'none' ) {
document.getEle mentById( elemID ).style.display =
'block';
}
else {
document.getEle mentById( elemID ).style.display =
'none';
}
}
</script>

<body>
<input type="checkbox" name="box1"
onclick="elemDi splayToggle(cho ices)" 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 1932

"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>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>

<script LANGUAGE="JavaS cript">
function elemDisplayTogg le (elemID) {
if ( document.getEle mentById( elemID ).style.display ==
'none' ) {
document.getEle mentById( elemID ).style.display =
'block';
}
else {
document.getEle mentById( elemID ).style.display =
'none';
}
}
</script>

<body>
<input type="checkbox" name="box1"
onclick="elemDi splayToggle(cho ices)" 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="elemDi splayToggle('ch oices')"

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="elemDi splayToggle('ch oices')"

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="JavaS cript" type="text/javascript">
<!--
function toggleSelect (select) {
if (!select.disabl ed) {
select.disabled = true;
}
else {
select.disabled = false;
}
}
//-->
</script>
</head>
<body>

<input type="checkbox" name="box1"
onclick="toggle Select(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.disabl ed) {
select.disable d = true;
}
else {
select.disable d = false;
}
}


Naive.

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

--
© 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.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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
553
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 http-equiv=Content-Type content="text/html; charset=iso-8859-1"> <SCRIPT type=text/javascript> <!--//
6
1377
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 Transitional//EN"> <HTML><HEAD><TITLE>Untitled Document</TITLE> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
0
2234
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 checkbox list. The problem is I'm unable to raise an event when I select any of the checkboxes. Following is the code: Could you guys please help me on this issue.
1
840
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 controlling the visibility of columns in the DataGrid control. The problem usually comes down to one fact. The DataGrid has a property called AutoGenerateColumns. The default value is "True". This means that when AutoGenerateColumns is set to True,...
1
1479
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() for(int i = 0; i < 5; i++ ListItem li = new ListItem(i.ToString(), i.ToString())
1
2619
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 CheckBox and click the HyperLink (NavigateURL set to WebForm1.aspx), the CheckBox lost it's state. I would assume that this is by design (now that I read ASP.NET in a nutshell) where it describes a HyperLink control action as 'navigates from one...
9
3250
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 handle it like a regular textbox? If so, how? Question#2 What is the best way of showing data that is linked to other data? Example: Paul's ID is 1. If I select Paul in a combo box, how can I make a textbox get Paul's ID from the table...
11
3209
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
1364
by: uraliar | last post by:
Hello! What should I do to call a list box every time I clicked a checkbox? Thanks!
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10330
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10153
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9952
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7500
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.