From: HerbF on
HerbF(a)earthlink.net wrote:

>Stefan Weiss wrote:
>
Solved. The issue was not with addressing the button array. The cookie
value was incorrect and that caused the exception.

Thanks for your help, Stefan.

Herb
From: Stefan Weiss on
On 26/04/10 16:27, HerbF(a)earthlink.net wrote:
> Stefan Weiss wrote:
>
>>On 26/04/10 07:30, HerbF(a)earthlink.net wrote:
>>> Stefan Weiss wrote:
>>>>On 26/04/10 02:47, HerbF(a)earthlink.net wrote:
>>>>> I have a menu of radio buttons in a form I named form1. Each radio button
>>>>> is named 'p1p6.' I store the value of which button is selected in an
>>>>> array named 'edit_array.' When I try to select a button using data in the
>>>>> array, as:
>>>>>
>>>>> document.forms["form1"].elements["p1p6"][edit_array[3]].checked=true;
>>>>>
>>>>> It throws an error: 'uncaught exception.' What am I doing wrong?
>>>>
>>>> document.forms["form1"].elements["p1p6"]
>>>>
>>>>is a NodeList (similar to an array of nodes). You need to access the
>>>>radio button you're interested in by its index (or with the item()
>>>>method), not by its value. I don't know the rest of your script, but
>>>>this might work:
>>>>
>>>> document.forms["form1"].elements["p1p6"][3].checked = true;
>>>>
>>>>BTW, if the form and element names are fixed (and valid JS identifiers),
>>>>you can also write the same line as
>>>>
>>>> document.forms.form1.elements.p1p6[3].checked = true;
>>>
>>> edit_array[n] is the selected the radio button element, not [3]. IOW,
>>> edit_array[3] is simply a stored value...not necessarily 3.
>>
>>If edit_array[n] is an input element, you can just use it directly:
>>
>> edit_array[n].checked = true;
>
> No. Information is stored in a cookie. I read in the cookie and split its
> content to form an array I am calling edit_array.
>
> I want to use the value stored as edit_array[3] to select one of several
> radio button input elements in a menu named p1p6.

You said edit_array[n] referenced an *element*. If edit_array[n] is
actually the *value*, you'll have to iterate over your radio buttons and
find which one the value belongs to.

function findRadioBtn (buttons, value) {
for (var i = 0; i < buttons.length; ++i) {
if (buttons[i].value == value) {
return buttons[i];
}
}
}

var radio = findRadioBtn(document.forms.form1.elements.p1p6,
edit_array[3]);
if (radio) {
radio.checked = true;
}


--
stefan