PDA

View Full Version : make selected item centered in <select>?


V@no
02-07-2003, 10:43 AM
is that possible make default selected item be on the center in <select> ?
I did an avatar script, that changes avatar in user's profile, so, I'd like when user open the page to change his avatar, his avatar was selected in be in the middle of visible on screen selection (not on the middle of whole list ;) )
by default selected value is always on top of visible list...

another question, in other fields, like <input> when user press "enter" it works as if he clicked on SUBMIT button.
"enter" key doesnt work in <select> though. so, is there a way to use "enter" key there too?

thanks.

cg9com
02-07-2003, 03:56 PM
i dont think you can center text inside of a select element.
this (http://www.codingforums.com/showthread.php?s=&threadid=13864) may help you on the enter thing.

arnyinc
02-07-2003, 04:25 PM
Not sure how many people would think to use it, but this should work.

<select onkeypress="if(window.event.keyCode==13){this.form.submit();}">

V@no
02-07-2003, 06:58 PM
so, what u are saying I can not make selected item in the list be on the middle like this? http://home.attbi.com/~vanowm/av2.gif

and thanks for the ENTER key :D

beetle
02-07-2003, 07:47 PM
<script type="text/javascript">
function setSelect()
{
var sel = document.formName.elementName;
sel.selectedIndex = Math.floor( sel.options.length / 2 );
}
</script>

<body onload="setSelect()">