T
Tyrone Slothrop
I am coding a search form which carries the values to an identical
form on the search results page. A "Clear Fields" button to remove
the values from the previous search is required. Ideally I would
prefer a generic script to do this. I had no problems with the script
until I had to deal with the radio elements.
Following is the problem part of the code:
function resetFields()
{
var len = document.form.elements.length;
for (var i=0; i<len; i++)
{
if (document.form.elements.type == 'radio')
{
var radioGrp = document.form.elements.name;
radioGrp[0].checked = true;
}
}
}
I understand each radio button is an element and assumed that, once
the name is defined, each time the radio element of the same name is
encountered in the script it would be treated as an array
nevertheless. It seems that this is a false assumption since the
radio is not reseting to the "0" value of the group.
What am I doing (or assuming) wrong?
TIA!
form on the search results page. A "Clear Fields" button to remove
the values from the previous search is required. Ideally I would
prefer a generic script to do this. I had no problems with the script
until I had to deal with the radio elements.
Following is the problem part of the code:
function resetFields()
{
var len = document.form.elements.length;
for (var i=0; i<len; i++)
{
if (document.form.elements.type == 'radio')
{
var radioGrp = document.form.elements.name;
radioGrp[0].checked = true;
}
}
}
I understand each radio button is an element and assumed that, once
the name is defined, each time the radio element of the same name is
encountered in the script it would be treated as an array
nevertheless. It seems that this is a false assumption since the
radio is not reseting to the "0" value of the group.
What am I doing (or assuming) wrong?
TIA!