OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   Re: [xml-dev] trying to get the text of a select box in reusablefunction

[ 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
> select object.  I do not know the name of the select, I am walking through
> 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 =
> 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++){
        // the type of select elements starts with "select"
        if (el!=select&&el.type.indexOf('select')==0){

if a select element is named "s1", in form "f1", you could call it like


You should be able to do something very much like this.

Tom P


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS