View Full Version : Reading the Radio Button Label

06-18-2004, 11:31 PM
Hello, I am new to JS and have a question which I cannot seem to find an answer. I want to read the text label assigned to a radio button (not the value and not the name), and I have not been able to find a way to do it. All of the sources I have referenced say the text label is not part of the radio button, but do not give you a way to retrieve it from a form.

Here is an example of the assignment statement I am using for the radio button creation:

<input TYPE="radio" NAME="support_requested_by" VALUE="PPE">Pre Production Engineering

What I need is to be able to get the "Pre Production Engineering" text and assign it to a variable. Is this possible?


06-19-2004, 03:50 AM
Here are a couple of ways:

<input TYPE="radio" VALUE="PPE" onclick="alert(document.getElementById(this.value).innerHTML"><label id="PPE">Pre Production Engineering</label>

<span><input TYPE="radio" onclick="alert(parentNode.getElementsByTagName('LABEL')[0].innerHTML)"><label>Pre Production Engineering</label></span>

06-19-2004, 03:55 AM
What I should have probably put in the original post is that I am creating a printer friendly document from an existing HTML page and need to read the form to get the labels (not the values or names) for the radio buttons and check boxes. Is there a way to do this?

06-19-2004, 04:15 AM
Well, no, not intrinsically. You have to code it.

Do my examples not give you the "text label assigned to a radio button (not the value and not the name)" ?

06-19-2004, 04:27 AM
Not exactly. What I get is a pop-up window with the words "Pre Production Engineer" as the text in the pop-up.

06-19-2004, 04:43 AM
Unless I'm misunderstanding your definition of a text label, the words "Pre Production Engineer" are just that.

The alert (pop-up window) was just a way of displaying that text, for demonstration.