473,837 Members | 1,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

An oddity when clicking checkbox

Hi,

Newbish on JS here. Found this script on the web and it does what I want
in FF, but works oddly in IE. When I check the box in IE nothing
happens, but when I click on the body after the box is checked it
displays the dropdown. Any ideas on how to make this work correctly in
IE (displaying the dropdown when box checked)? Thanks for your help.

<html>
<head>
<title>Untitled </title>
<script language="javas cript" type="text/javascript">
<!--
function categorychanged (enable) {
if (enable) {
document.form.c ategory_parent. style.display=" inline";
}
else {
document.form.c ategory_parent. style.display=" none";
}
}
//-->
</script>
</head>
<body>
<form name="form">
<span>
<input type="checkbox" name="category_ level"
onchange="categ orychanged(this .checked)">
<select name="category_ parent" style="display: none">
<option value="1">1</option>
<option value="2">2</option>
</select>
</span>
</form>
</body>
</html>


--
Patrick A. Smith Assistant System Administrator
Ocean Circulation Group – USF - College of Marine Science
http://ocgweb.marine.usf.edu

The trouble with doing something right the first time is that nobody
appreciates how difficult it was. - La Rochefoucauld

Nov 17 '08 #1
3 1867
Patrick wrote:
<input type="checkbox" name="category_ level"
onchange="categ orychanged(this .checked)">
Don't use onchange, use
onclick="catego rychanged(this. checked)"
instead.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 17 '08 #2
Martin Honnen wrote:
Patrick wrote:
><input type="checkbox" name="category_ level"
onchange="cate gorychanged(thi s.checked)">

Don't use onchange, use
onclick="catego rychanged(this. checked)"
instead.
Yep, that worked. Thanks Martin. You rock! I figured it was someting as
simple as that, but my limited knowledge of JS precluded me from
figuring that out. Can I ask another question?

What would I do to use the same script over for other checkboxes and
dropdowns so that I wouldn't have to have the same script over and over
with only changing the name="category_ level" and name="category_ parent"
for each use?

Posted script/form parts again to save you from looking up the earlier
post.

<!--
function categorychanged (enable) {
if (enable) {
document.form.c ategory_parent. style.display=" inline";
}
else {
document.form.c ategory_parent. style.display=" none";
}
}
//-->
<form name="form">
<input type="checkbox" name="category_ level"
onclick="catego rychanged(this. checked)">
<select name="category_ parent" style="display: none">
<option value="1">1</option>
<option value="2">2</option>
</select>

--
Patrick

Go Bulls!
Nov 17 '08 #3
Patrick wrote:
Martin Honnen wrote:
>Patrick wrote:
>><input type="checkbox" name="category_ level"
onchange="cat egorychanged(th is.checked)">
Don't use onchange, use
onclick="catego rychanged(this. checked)"
instead.

Yep, that worked. Thanks Martin. You rock! I figured it was someting as
simple as that, but my limited knowledge of JS precluded me from
figuring that out.
[1]
This is not a matter of (limited) JS knowledge but of (limited) knowledge
about the DOM. The `change' event is supposed to occur when the control's
value changes *and* it loses focus. Clicking/activating a checkbox makes
it change value but does not make it lose focus. So the `onchange' event
handler is an unsuitable one here.
Can I ask another question?
No ;-)
What would I do to use the same script over for other checkboxes and
dropdowns so that I wouldn't have to have the same script over and over
with only changing the name="category_ level" and name="category_ parent"
for each use?
Since the `click' event bubbles, you would make use of event bubbling.
(See? [^1])

<http://www.w3.org/TR/DOM-Level-2-Events/events.html#Eve nts-flow-bubbling>
<http://www.w3.org/TR/DOM-Level-3-Events/events.html#Eve nts-flow>
<http://groups.google.c om/groups?as_q=eve nt+bubbling&as_ ugroup=comp.lan g.javascript&sc oring=d&filter= 0>
[...]
<!--
This does not belong there, remove it.
function categorychanged (enable) {
if (enable) {
document.form.c ategory_parent. style.display=" inline";
}
else {
document.form.c ategory_parent. style.display=" none";
}
}
You really should indent the content of Block statements.
//-->
Superfluous; remove that, too.
<form name="form">
The required `action' attribute is missing, the `name' attribute is probably
superfluous.

<http://validator.w3.or g/>
<input type="checkbox" name="category_ level"
onclick="catego rychanged(this. checked)">
<select name="category_ parent" style="display: none">
Bad idea. If client-side script support is not present or disabled, and CSS
support is present and enabled, there will be no way for the user to access
that control. You should hide it dynamically with DOM scripting instead, like

<body onload="documen t.forms[0].elements['category_paren t'].style.display
= 'none'">
<option value="1">1</option>
<option value="2">2</option>
It should be possible to omit the `value' attributes in these cases:

<http://www.w3.org/TR/html4/interact/forms.html#h-17.6>
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Nov 17 '08 #4

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

Similar topics

0
1364
by: Tallgeese | last post by:
We developed an in-process COM object for our own application. A toolbar button is used to activate the COM object. But when the COM object loaded, the HTML help hang when clicking the "List Topics" in "Search" tab. The HTML help work nornally without loading the COM. Can anyone provide some starting points, so that I can look at the problem ? Thanks in advacne.
3
1672
by: Andrew Wrigley | last post by:
Hi I have what seems a corruption of an mdb that is not solved by the decompile command line trick. The problem appears when clicking on a subform control (check box) that has a event handler associated with it. Everything works ok, until I click on the check box, whereupon Access fails with an application error. It appears that execution never
0
2019
by: jeff | last post by:
is there a way to display an hourglass for the client's cursor when clicking a button running server-side code? thanks.
4
10687
by: James Brett | last post by:
I have one form on the page but have multiple submit buttons for different elements. When clicking on a button not associated with the required elements the validator popup still comes up. How can I disable requiredfieldvalidator fields when I click on non associated button? Cheers James
2
3222
by: André | last post by:
Hi, I made a detailsview containing several fields for inserting only. I also made a dropdownlist which is invisible at start. Now, when clicking in a particular textbox, the dropdownlist must become visible (in order to put the selected value of the dropdownlist into the textbox of the detailsgrid.). I must say, the detailsview contains textboxes, but also a checkbox. I tried a lot of things, but i don't know which events to take:
1
1209
by: karups | last post by:
Hi I have binded a dataset to my datagrid. Datagrid is present inside a >DIV></DIVtag of specific height. Only 5 records will be visible at a time when i edit the 10th record, the page refreshes and the datagrid goes to its top position. I have to search for the edited item inside the div tag by scrolling and then edit it..
0
912
by: karups | last post by:
Hi I have binded a dataset to my datagrid. Datagrid is present inside a >DIV></DIVtag of specific height. Only 5 records will be visible at a time when i edit the 10th record, the page refreshes and the datagrid goes to its top position. I have to search for the edited item inside the div tag by scrolling and then edit it..
3
17320
by: BaseballGraphs | last post by:
Hello, I am looking to disable all checkboxes when one checkbox is selected. I cannot use radio buttons, so I need to be able to disable the checkboxes if 1 checkbox has been selected. Can you please assist if you know how to perform this sort of function. Thanks very much.
0
9851
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10902
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
10583
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...
1
10642
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7013
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
5680
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
5863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4481
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
2
4060
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.