tags:

views:

39

answers:

4

<select><option><input type="checkbox" />Headache</option></select>

By using the above code i did't get a check box inside a dropdown list.Can you suggest me , how should i proceed.

+2  A: 

You can't have an input control inside a select element. You'll have to create the drop-down using JavaScript, without using the select element at all.

Matti Virkkunen
A: 

That's not possible with "plain" HTML, you'll need to grab JavaScript to progressively enhance a plain dropdown into such a dropdown with help of <ul><li> elements and a good shot of CSS. You can find here an overview of what's all possible with jQuery (a JavaScript library), such as the jQuery dropdown checklist.

It's pretty simple, just import the desired JS libraries and apply it:

<!doctype html>
<html lang="en">
    <head>
        <title>Dropdown with checkboxes.</title>
        <script src="jquery.js"></script>
        <script src="dropdownchecklist.js"></script>
        <script>
            $(document).ready(function() {
                $("#select_id").dropdownchecklist();
            });
        </script>
    </head>
    <body>
        <select id="select_id">
            ...
        </select>
    </body>
</html>

That's all.

BalusC
@BalusC: thanks , I have tried it with modification but code is not working ,what should i do? In this code combo box is created withoutcheck box.Please elaborate........
Radhe
@BalusC: is there any plugin required for jquery?
Radhe
Only JavaScript and every webbrowser supports it.
BalusC
A: 

Another approach on top of BalusC's one is to actually develop your own custom UI element. Unfortunately, this is usually (or always?) browser-specific.

I know you can do that for Firefox using XUL.

I'm sure you can do some ActiveX tricks for IE though no clue how.

DVK
Sounds like a whole lot of effort for something that be done with some JS and CSS
Matti Virkkunen
For this specific design, possibly. Not always
DVK
+1  A: 

The reason that didn't work is that form elements don't nest like that. Fortunately, there's a jquery plugin that can do what you want. http://abeautifulsite.net/2008/04/jquery-multiselect/

Rookwood