[thelist] JavaScript: Accessing selectedIndex
Matthew Fischer
mfischer at e-fishsolutions.com
Fri Nov 3 13:48:47 CST 2000
For your onChange event, you can simply use:
<select name='DReviewMonth' size='1' onchange=DateModify(this)>
If what you are trying to do is find out how many choices in your select list and which on is selected, you should use:
function DateModify(TheSelect)
{
alert(TheSelect + " - " + TheSelect.options.length + " - " + TheSelect.selectedIndex);
...
If you want to know the value of the selectedIndex instead of the number, use:
function DateModify(TheSelect)
{
alert(TheSelect + " - " + TheSelect.options.length + " - " + TheSelect.selectedIndex.value);
...
And remeber, if the fifth item in your select is the chosen one, the selectedIndex is [4], because the first item is [0].
On 11/3/00 at 1:54 PM, talleman at autobex.com (Tab Alleman) wrote:
>
> In the body of my page, I have the following form element:
>
> <select name='DReviewMonth' size='1' onchange=DateModify('DReviewMonth')>
> ...
>
> Ok, then in my script, the beginning of DateModify() goes like this:
>
> function DateModify(TheSelect)
> {
> alert(TheSelect + " - " + TheSelect.length + " - " +
> TheSelect.selectedIndex);
> ...
>
> HOWEVER, when I change the select box, the resulting alert box displays:
>
> DReviewMonth - 12 - undefined
>
> Why? Why is it accessing the .length property as advertised, but not the
> selectedIndex property? I don't see anything wrong with my script.. does
> anybody?
>
>
> ---------------------------------------
> For unsubscribe and other options, including
> the Tip Harvester and archive of TheList go to:
> http://lists.evolt.org Workers of the Web, evolt !
--
Matt Fischer || e-fish solutions, inc (e) \\\\\__ o
<mfischer at e-fishsolutions.com> (e) / o \ o
<http://www.e-fishsolutions.com> (e) (( <
877.WEB.FISH || 203.272.2987 (e) \+_+_+_/
Fax 800.203.5816 (e) \|/
More information about the thelist
mailing list