I’m trying to have a specific input field to be enabled onload, only if a specific radio button is checked… after some hours, I’ve come with something like this:
The form id is “pedidoOnline”:
function activaInputOnload()
{
//stores on an array all the fieldsets on our document:
fieldsetArray = document.getElementsByTagName("fieldset");
*
//for each occurence of fieldset:
for (var i = 0; i < fieldsetArray.length; i++)
{
//stores the fieldset name atribute value into a variable radioName - so I hope. :s
var radioName = document.pedidoOnline.fieldsetArray[i].id;
//saves all the radio buttons of the actual fieldset
//note: the fieldset id is equal to the radio name on a given fieldset.
var radiosArray = document.pedidoOnline.fieldsetArray[i].getElementByName[radioName];
//there will be only one 'outroTxt' input per fieldset. Hope getElementById doesn't return an array, it will be a 1 element array. :s'
var inputFieldOutro = document.pedidoOnline.fieldsetArray[i].getElementById(match(/^outroTxt/));
//for all radios on this fieldset
for (var j=0; j < radiosArray.length; j++)
{
//if the fieldset radios starts with a string outro and, is checked:
if ( (radiosArray[j].id.match(/^outro/)) && (radiosArray[j].checked) )
{
//the input field should be active (cross-browser active :s)
inputFieldOutro.disabled=false;
inputFieldOutro.focus=true;
inputFieldOutro.click=true;
}
}
}
}
However, I’m having an error:
document.pedidoOnline.fieldsetArray is undefined
on this line:
var fieldsetName = document.pedidoOnline.fieldsetArray[i].id;
The error is a little thing compared with the issues all over this code, I realise that, and I hope you can give me some lights here… :s
Best regards,
Márcio
ps- I don’t need this to be necessarily on load, but it needs to be active if a server side validation returns errors. So I thought, onLoad. But if there are other ways to make js to communicate with php, please let me know.