Re: Javascript Bug?
- From: RobG <rgqld@xxxxxxxxxxxx>
- Date: Fri, 30 Sep 2005 07:13:26 +1000
Lee wrote:
Marshall Dudley said:
[...]
This works fine if there are 2 or more radio buttons, but if there is only one, it fails. The alert if I uncomment it says that the length is undefined, when it should be 1. Anyone know what the problem is and how I can get around it?
It's got nothing to do with Javascript, it's how the DOM is defined. If there is only one form control with a given name, it's not modeled as an array, and so it has no length attribute.
Further, radio buttons should never be used singly. If a single checkable element is indicated, it should be a checkbox. Try to uncheck a solitary radio button.
One radio button should always be selected (but browsers don't enforce it). Once a single button is selected, there are no others to check so you can't uncheck a solo button it without re-setting the form. Some browser developer may also decide to check the first radio button by default if the page author hasn't decided which one should be checked by default (I don't know of any that do so, but the specification could be interpreted that way).
<URL:http://www.w3.org/TR/html4/interact/forms.html#radio>
[...]
-- Rob .
- Follow-Ups:
- Re: Javascript Bug?
- From: Robert
- Re: Javascript Bug?
- References:
- Javascript Bug?
- From: Marshall Dudley
- Javascript Bug?
- Prev by Date: Re: Javascript Bug?
- Next by Date: Re: Javascript Bug?
- Previous by thread: Re: Javascript Bug?
- Next by thread: Re: Javascript Bug?
- Index(es):