Hi,

For single-select select boxes, you can use `selectedIndex`:

    var selbox, selindex, option;

    selbox = $('country');
    selindex = selbox.selectedIndex;
    if (selbox.selectedIndex < 0) {
        alert("None selected");
    }
    else {
        option = selbox.options[selindex];
        alert("val = '" + option.value + "', text = '" + option.text +
"'");
    }

For multi-selects you loop through the `options` array looking for
options with the `selected` flag set, and grab the `value` and `text`
from them.

Somewhat OT, but I'd close[1] those option tags. (That's an HTML 4.01
spec; couldn't immediately find the relevant bit of the massive HTML5
spec.)

(BTW, I used the select box's ID to retrieve it because this didn't
work in IE:

    var form = $('billing');
    var customerCountry = form['billing[country]'].getValue();

The second line failed. I didn't debug it (since I don't do forms that
way); the select box already had an ID so I used that.)

[1] http://www.w3.org/TR/html401/interact/forms.html#edef-OPTION

HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com

On Jan 25, 5:09 pm, J Norton <jus...@champs-elysees.com> wrote:
> Hello,
>
> I can get the values of a select list as follows:
>
> <select name="billing[country]" id="country" class="validate-select"
> title="Country" ><option value="">&<option value="GB">United Kingdom</
> option>...etc
>
> var form = $('billing');
> var customerCountry = form['billing[country]'].getValue();
>
> But I can't seem to retreive the actual text string (United Kingdom),
> how do I do that?
>
> Thank you,
> Justin.

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to