My error...
A checkbox is a type of <input> element which is an empty element, meaning that it doesn't have a closing tag </input>. So there is no enclosed content, text or otherwise. So you have to create a predictable relationship between the two. One way (of probably many) is to enclose the text in a <span> element with an id that is related to the name of the checkbox it's related to. Another is to add a "custom" attribute to the element that duplicates the text that follows it. Personally I'd use the 1st method, but I thought I'd give you a choice.
The following is an example that works in at least IE4+ (and probably NN4+ as well - I don't do NN)... The <span> has been in IE since 3.0 but not accessible from script until 4.0.
<HTML><HEAD></HEAD>
<BODY>
<!-- related by name... --->
<INPUT name=checkbox1 type=checkbox value="12345"
onclick="alert(document.all[this.name+'text'].innerText)">
<span id=checkbox1text>Checked Item 1</span>
<!-- custom "text" attribute --->
<INPUT name=checkbox2 type=checkbox value="12345"
onclick="alert(this.text)"
text="Checked Item 2">Checked Item 2
</BODY>
</HTML>
--
Michael Harris
Hi,
The .value property works but .innerText returns a blank.
Anything I'm doing wrong?
Here is my code:
for ( var i = 0;i < form.chkRowItem.length; i++ ) {
if ( form.chkRowItem[i].checked == "1" ) {
alert(form.chkRowItem[i].value);
alert(form.chkRowItem[i].innerText);
}
}
Thanks.
Brian Armstrong.
checkbox1.value
checkbox1.innerText
--
Michael Harris
Hi,
In an HTML form I need to capture both the value and displayed text of a
checkbox control? How do I do this?
Example:
<INPUT name=checkbox1 value="12345">Checked Item</INPUT>
I want to grab both the value "12345" and "Checked Item".
Thanks.
Brian Armstrong.