[Javascript] Positioning within a select box

Mark Christie MChristie at avsgroup.com
Tue Mar 20 16:43:30 CST 2001


Thanx, Ben...Gotta preserve the order too...The app has an international
audience...

So far, here is my kludge:

function checkBack() {
	var objLangSelect = document.forms.frmLanguage.iLangSelect;
	var iLangCount = 0;
	
	for(i=0; i < objLangSelect.length; ++i)
		if(objLangSelect[i].selected)
			++iLangCount;

	if(!iLangCount) {
		objLangSelect.selectedIndex = 13;
//positions toward the end of list
		objLangSelect.selectedIndex = 8;
//scrolls back and positions on English
		objLangSelect.selectedIndex = -1;
//unselects English
	}
}

It's ugly, but it works lovely when first coming to the page and nothing is
selected.  But if I return to the page with previous selections, using
selectedIndex wipes them out.

Any ideas?

Regards,
   -Mark C.


-----Original Message-----
From: Ben [mailto:ben at babelfish.co.uk]
Sent: Tuesday, March 20, 2001 4:06 PM
To: javascript at LaTech.edu
Subject: RE: [Javascript] Positioning within a select box


> Greetings, list...
>
> I have a list of about 30 or so languages to choose from in a select box,
> from Arabic to Thai.  Since the list is alphabetized, when the
> page pops up,
> Arabic is the top selection.  What I want to do is position the
> display such
> that English, the 9th language in the list, is the top selection.
>  How can I
> do this?
>
> Regards,
>    -Mark C.

Mark.  Did you want English at the top of the list or just to be automaticly
selected when the page loads?  If you want it at the top of the list then
put the English <option> entry directly after the opening <select> tag.  If
you want English to be automaticly selected then add the "selected"
attribute to the English <option> tag, like this:

	<option selected>English</option>

I recommend pre-selecting ov er re-ordering, but this can sometimes offend
non-English-based visitors to the site.

Hope this helps.

 .b


_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
http://www.LaTech.edu/mailman/listinfo/javascript




More information about the Javascript mailing list