views:

451

answers:

4

I'm trying to build a checkbox list within a select list (like the one for countries here: link text)

I'm using Asp.net MVC so it needs to be pure/html &| javascript/JQuery. Is this possable? Or is there already a prebuild one I could download load?

Thanks

Ripped HTML/CSS:

 <html xmlns="http://www.w3.org/1999/xhtml" >
<head>

<style type="text/css">
body {  background-color: #FFFFFF; font-family: Tahoma; font-size: 11px; }

/* Control Skin */
input { font: normal 11px Tahoma; }
div.ctrl { background-color: window; border: solid 1px ThreeDLightShadow; vertical-align: top; margin: 0; padding: 0;  width: 268px; }
input.Button { background: #2F89BD url('images/btn_default%20gradient.gif') repeat-x; cursor: pointer;
                height: 24px; color: #FFF; border: solid 1px #2F82BE; padding: 0 10px; width: auto;
                overflow: visible; }
input.TextBox { border: solid 1px ThreeDLightShadow; height: 16px; padding-top: 2px; text-indent: 2px; width: 150px; }

/* For MultiSelectControl */
.ms_multiSelector { position: absolute; display:inline ; border: 1px solid ThreeDLightShadow; width: 268px; z-index: 100; }
.MultiSelectControl_txtInput { width: 240px; border: none 0; margin: 5px 0 0 5px; padding: 0; vertical-align: top; }
.ms_selectListWrapper { padding: 0; margin: 0; }
.ms_selectList { background-color: #FFFFFF; overflow: auto; height: 265px; _height: 150px; /* For IE 6 */ }
.ms_chkSelectAll { padding-left: 3px; }
.selectList_Wrapper { padding: 0; margin: 0; }
.multiSelectorCountry { position: relative; clear: both; display: none; border: 1px solid ThreeDLightShadow; width: 275px; }
.multiSelector { position: absolute; visibility: hidden; border: 1px solid ThreeDLightShadow; width: 275px; }
.mutliselect_container { padding: 0; margin: 0; border: 0; display: inline; }
.chkSelectAll { padding-left: 3px; }
.selectList { background-color: #FFFFFF; overflow: auto; height: 200px; _height: 150px; /* For IE 6 */ }
.chklstSelect INPUT { float: left; width: 20px; /* To align the chkbox text in FF */ }
.chklstSelect LABEL { text-align: left; float: right; width: 230px; /* To align the chkbox text in FF */ }
#imgMultiSelectArrow { width: 20px; height: 20px; margin-left: 300px; padding-left: 300px; }
.multiselect_close { padding: 4px 0; float: right; width: 65px; background: transparent url(https://careers.microsoft.com/images/close_btn.gif) no-repeat 33px center; }

</style>




<title>Untitled Page</title>
</head>
<body>
<div class="ctrl" >
<input  type="text" value="Software Engineering: Development" readonly="readonly"  class="MultiSelectControl_txtInput"  />
<img  onmouseover="this.src='https://careers.microsoft.com/Images/mm_dropdown_20x20_hover.gif'" onmouseout="this.src='https://careers.microsoft.com/Images/mm_dropdown_20x20.gif'"  src="https://careers.microsoft.com/Images/mm_dropdown_20x20.gif" alt="Show/Hide" style="height:20px;width:20px;border-width:0px;" />
</div>
<div  class="ms_multiSelector">

    <div id="selectList" class="ms_selectList">
        <input  type="checkbox" value="allcountry" class="ms_chkSelectAll" />
        <span class="ms_chkSelectAll"  >Select All</span>

<div>
        <input  type='checkbox'  value='1'  />
        <label>Business Services & Administration</label>
        <br />
        <input type='checkbox'  value='37'  />
        <label>Customer Service & Support</label>
        <br />
     </div>
  </div>

</div>


</body>
</html>
+1  A: 

Maybe this is not a real answer, but anyway:

That's not a standard HTML control, they built it with a series of text inputs and divs, you'd have to do LOTS of work to reproduce that behavior, so that it works (possibly with any browser)...

I'm not aware of any pre-built helpers for MVC, maybe there is something for JQuery? Anyway, if you can't find one and you had to do that manually, maybe you should choose other means with more standard components (or revert to flash or silverlight which are much more convenitent for this kind of customizations).

Palantir
A: 

This is not a standard HTML form control, it has been custom built by the developers.

I'm not aware of any open source solutions that exist that will reproduce this behaviour for you. I'm afraid it looks unlikely you can deliver this without more effort than it will be worth.

Evernoob
+1  A: 

In HTML the only valid children of the select element are option and optgroup. I strongly recommend creating any sort of non-standard form control as you will be defeating accessibility. I recommend you use standard form controls in the standard manner with label elements only. You can modify the appearance and interactivity of those form controls to your hearts content using CSS and JavaScript, except don't alter the visual flow order or tab order as that also defeats accessibility.

The accessible alternative to the Microsoft form is to use a standard select list with the "multiple" attribute so that multiple options can be selected from a single list. Here is an example:

<select id="myselectlist" name="myselectlist" multiple="multiple">
    <option value="option 1">option 1</option>
</select>

You could use CSS to fake the appearance of checkboxes with the appearance of a checked checkbox as a background graphic that appears from the option's pseudo class of "active". I would not go much further than that however.

+1  A: 

You could try just leaving it as is pretty much except add

.ms_selectList{ display: none; }

Add the above to what you already have for ms_selectList

Then in jquery have a click function of some kind that will make the ms_selectList display clock essentially making it appear to be like a select box when its really just an absolutely positioned div tag with a bunch of checkboxes inside.

And the jquery ought to be something like this,

$(document).ready(function(){

    $('.ctrl').click(function(){
     $('#selectList').toggle();
    });

})
Sir David of Lee
I ended up using this one: http://code.google.com/p/dropdown-check-list/
Lee Smith