salivan salivan - 2 years ago 420
Javascript Question

can I use ul li instead of select dropdown and with jquery make it part of a form?

I went really long way trying to rewrite select to ul li and style it accordingly. But I'm getting really annoyed with the weight of code and minor annoyances on the way.

So I'm thinking to ditch the idea completely, and just use normal ul li menu and some kind of javascript to make it function like select (for form submission etc).

So is this possible? any example code you can give me?

My concerns is Cross browser compatibility.

Answer Source

Lovely idea. I just made one in the fiddle check it out here.


    <li class="init">[SELECT]</li>
    <li data-value="value 1">Option 1</li>
    <li data-value="value 2">Option 2</li>
    <li data-value="value 3">Option 3</li>


$("ul").on("click", ".init", function() {

var allOptions = $("ul").children('li:not(.init)');
$("ul").on("click", "li:not(.init)", function() {


ul { 
    height: 30px;
    width: 150px;
    border: 1px #000 solid;
ul li { padding: 5px 10px; z-index: 2; }
ul li:not(.init) { float: left; width: 130px; display: none; background: #ddd; }
ul li:not(.init):hover, ul li.selected:not(.init) { background: #09f; }
li.init { cursor: pointer; }

a#submit { z-index: 1; }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download