abs wrote:
Is there any way to get to a select element by the order it apperas
in the code ? For example, I'd like to get the value of first option
of second <select> element.
I don't think there is any need to do something like this, since you
can give your select elements names and IDs. If you want to do so
anyway, you could use something like
function getValue(nForm, nSelect, nOption) {
var oForm, i, nElems, oElem, sValue, oOption;
if (!isNaN(nForm)) {
oForm = document.forms[nForm];
if (oForm) {
for (nElems=oForm.length, i=0; i<nElems; i++) {
oElem = oForm.elements[i];
if (oElem.type.indexOf("select") == 0) {
nSelect--;
if (nSelect < 0) {
oOption = oElem.options[nOption];
sValue = oOption && oOption.value;
break;
}
}
}
}
}
return sValue;
}
getValue(2,1,4) retrieves the value of the fifth option of the second
select control in the third form in the document. If there are less
options or select controls or forms than requested, getValue() returns
undefined.
ciao, dhgm