1

Hey guys i need some check boxes inside a dropdownlist which allow to select multiple check boxes and then save it to database.

I dont know how and where to start. any one please help me ???

                <optgroup label="Rooms">
                    <option value="option_1"> 1</option>
                    <option value="option_2"> 2</option>
                    <option value="option_3"> 3</option>
                    <option value="option_4"> 4</option>
                    <option value="option_5"> 5</option>
                    <option value="option_6"> Modren</option>
                    <option value="option_7">Semi Modren</option>

                </optgroup>
            </select>
3

2 Answers 2

1

hi you can do this by using jquery plugin.

http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/

Sign up to request clarification or add additional context in comments.

2 Comments

i think in below answer w00 has given you example of this plugin you just need to include the js files.
download the zip file from here and see the demos you will idea how to implement github.com/ehynds/jquery-ui-multiselect-widget
0

I hope you're using a Javascript library like jQuery or something similar. That way you can easily use a lib that converts a standard HTML multiselect to a dropdown with selectboxes, like in this example:

http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/

From there on you can do a form submission like you would normally do. For example:

<form method="POST" action="somefile.php">
    <select id="example" name="example[]" multiple="multiple">
        <option value="1">Option 1</option>
        <option value="2">Option 2</option>
        <option value="3">Option 3</option>
        <option value="4">Option 4</option>
        <option value="5">Option 5</option>
    </select>
</form>

<script>
    $("#example").multiselect();
</script>

(please note the name is example[] and NOT just example)

Then in PHP you can iterate through the selected checkboxes like this:

if ( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
    foreach ( $_POST['example'] as $index => $value )
    {
        echo $value . '<br />';
    }
}

1 Comment

@TariqHashemee No this will not create any problems. You have access to the selected values in the foreach loop. It depends on how your database is designed, how you want to store to selected values and what kind of lib. you're using (ie. mysqli or PDO). So its hard to give a direct example on how to do this, since you only know how your DB is designed and what you're using. But in anyway you can easily store the data in your database.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.