jQuery and ASP.NET

April 27, 2009

Using JavaScript to DropDown an HTML Select on MouseOver




An HTML SELECT can be programmatically dropdown on MouseOver using JavaScript. On MouseOut, we can get the SELECT to its default positions. Here's how to do it

<html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
title>Drop on Hover</title>
<
script type="text/javascript">
function
DropList() {
var n = document.getElementById("sel").options.length;
document.getElementById("sel").size = n;
}
</script>
</
head>
<
body>
<
div>
<
select id="sel" onmouseover="DropList()" onmouseout="this.size=1;">
<
option>One</option>
<
option>Two</option>
<
option>Three</option>
<
option>Four</option>
<
option>Five</option>
<
option>Six</option>
<
option>Seven</option>
<
option>Eight</option>
</
select>
</
div>
</
body>
</
html>

See a Live Demo.

image

On Mouse Hover

image


Bookmark this link on del.icio.us (saved by 0 users)

Did you like this post?
kick it on DotNetKicks.com
subscribe via rss subscribe via e-mail
print this post follow me on twitter
Others Also Read..

comments

4 Responses to "Using JavaScript to DropDown an HTML Select on MouseOver"
  1. Balaji said...
    August 26, 2009 2:45 PM

    Wow, I hadn't thought about it that way before. Good write up, very clearly written. Have you written previously about Using JavaScript to DropDown an HTML Select on MouseOver? I'd love to read more.

  2. Society for Handicapped said...
    August 27, 2009 9:59 AM
    This post has been removed by the author.
  3. Anonymous said...
    August 27, 2009 10:00 AM

    Kinda backwards moving IMO just because the select element can't be easily styled cross browser. What I'm looking for is an elegant way of turning a div into a select box. Any takers?

  4. Anonymous said...
    August 27, 2009 10:50 AM

    I've just started using the mega-dropdown menu code from here: http://www.javascriptkit.com/script/script2/jScale/

    It lets you drop down a div with any contents just by hovering over something....

    It is jQuery-based.

 

Copyright 2010 All Rights Reserved DevCurry.com by Suprotim Agarwal