Patrick wrote:
Martin Honnen wrote:
>Patrick wrote:
>><input type="checkbox" name="category_level"
onchange="categorychanged(this.checked)">
Don't use onchange, use
onclick="categorychanged(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#Events-flow-bubbling>
<http://www.w3.org/TR/DOM-Level-3-Events/events.html#Events-flow>
<http://groups.google.com/groups?as_q=event+bubbling&as_ugroup=comp.lang.jav ascript&scoring=d&filter=0>
[...]
<!--
This does not belong there, remove it.
function categorychanged(enable) {
if (enable) {
document.form.category_parent.style.display="inlin e";
}
else {
document.form.category_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.org/>
<input type="checkbox" name="category_level"
onclick="categorychanged(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="document.forms[0].elements['category_parent'].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