473,797 Members | 3,174 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 1863
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
1363
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
1670
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
2015
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
10685
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
3214
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
1208
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
910
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
17293
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
9685
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
9536
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
10245
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
10021
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
7559
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
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4131
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
3748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.