[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: trying to get the text of a select box in reusablefunction

select get text
[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


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.

Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.