[thelist] JavaScript: Accessing selectedIndex

Tab Alleman talleman at autobex.com
Fri Nov 3 14:03:43 CST 2000


beatcha to it.. here's the correct way to do what I described, in case
anybody here wants to use this exciting new technology themselves.. :)  My
conclusion is (as always) that JavaScript is a pain in the ass, and that's
why we get the big bucks.

	function DateModify(TheSelect)
		{
		if (TheSelect.selectedIndex == (TheSelect.length - 1))
			{
			var DateSelect;
			var YearSelect;
			DateSelect = TheSelect.name;
			YearSelect = TheSelect.name;
			DateSelect = DateSelect.replace(/Month/, "Date");
			YearSelect = YearSelect.replace(/Month/, "Year");
			document.forms[0].elements[DateSelect].selectedIndex =
(document.forms[0].elements[DateSelect].length - 1);
			document.forms[0].elements[YearSelect].selectedIndex =
(document.forms[0].elements[YearSelect].length - 1);
			return true;
			}
		}

-----Original Message-----
From: thelist-admin at lists.evolt.org
[mailto:thelist-admin at lists.evolt.org]On Behalf Of Tab Alleman
Sent: Friday, November 03, 2000 2:35 PM
To: thelist at lists.evolt.org
Subject: RE: [thelist] JavaScript: Accessing selectedIndex


*slapping forehead*   I would have to choose a name that had the same number
of letters as the select had options.  Thanks Scott.  That got me past one
error and on to the next.  The point of my function is that when the user
changes the month in the DReviewMonth box to the last option (which is
blank), it instantly sets the corresponding DReviewDate and DReviewYear
selects to their last options (which are blanks).  Here's how I'm trying to
do it:

	function DateModify(TheSelect)
		{
		if (TheSelect.selectedIndex == (TheSelect.length - 1))
			{
			var DateSelect;
			var YearSelect;
			DateSelect = TheSelect.name;
			YearSelect = TheSelect.name;
			DateSelect.replace(/Month/, "Date");
			YearSelect.replace(/Month/, "Year");
			alert(DateSelect);
			DateSelect.selectedIndex = (DateSelect.options.length - 1);
			YearSelect.selectedIndex = (YearSelect.options.length - 1);
			return true;
			}
		}

I'm apparently not doing the replace correctly though.  Doing an
alert(DateSelect); after the replace line still yields:  "DReviewMonth" --
it should be "DReviewDate".. right?





---------------------------------------
For unsubscribe and other options, including
the Tip Harvester and archive of TheList go to:
http://lists.evolt.org Workers of the Web, evolt !





More information about the thelist mailing list