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