[
Lists Home |
Date Index |
Thread Index
]
[Rochester, Dean]
>
> I am trying to write a reusable function that I can use to get the text of
a
> select object. I do not know the name of the select, I am walking through
a
> form.
>
Dean, this is not a javascript list. Please find one, it will be more
effective and less annoyng for everyone.
> Here is what I have tried. It does not like the use of the
>
> toString(elements[intLoop].getAttribute('name'))
>
> in the last line.
>
>
> strField = elements[intLoop].getAttribute('value');
> // if the field is a select box the value from the line above will
> // be null even if there is a value in the box.
> // you need the option selected value for the strField variable
> if (strField == null || strField == "") {
> var OptionsList =
> document.forms[0].toString(elements[intLoop].getAttribute('name'));
> strField =
>
document.forms[0].toString(document.forms[0].getAttribute('name')).options[O
> ptionsList.selectedIndex].text;
> }
>
Try to keep things simple where you can. Here's an example where I walk
through a form's elements to remove all selections in all select elements
except for the one select element that was passed into the function (this is
really part of a larger function) - it's not fully generic because the form
name "f1" is coded in, but obviously it would be easy to fix that:
function clearMost(select){//"select" is a select object
var els=document.f1.elements,e,el//f1 is the name of a form
for (e=0;e<els.length;e++){
el=els[e]
// the type of select elements starts with "select"
if (el!=select&&el.type.indexOf('select')==0){
el.selectedIndex=-1
}
}
}
if a select element is named "s1", in form "f1", you could call it like
this:
clearMost(document.f1.s1)
You should be able to do something very much like this.
Tom P
|