API TAY API TAY - 1 year ago 59
HTML Question

In select option , all options should be selected and the user should not be able to change it

I have to create a select dropdown using HTML in which the users have to select all options.

<select multiple>

<option value="thriller" selected>thriller</option>
<option value="action" selected >action</option>
<option value="horror" selected >horror</option>
<option value="romance" selected>romance</option>


If the users clicks on any option, only the particular option remains selected. I have to use the selected options to set up values using javascript.

Answer Source

If you have to do it only in HTML, the following code works

<select multiple>
<option value="thriller" selected disabled>thriller</option>
<option value="action" selected disabled>action</option>
<option value="horror" selected disabled>horror</option>
<option value="romance" selected disabled>romance</option>


However it wont work for IE and you will unable to post data.

In Javascript, this code will work

    <select multiple onclick="fun();">

Inside script tag, add the following code

    function fun()
            var sel = document.getElementById("sel");
            var length = sel.options.length;
            for(var i=0;i<length;i++)
                    sel.getElementsByTagName('option')[i].selected = 'selected';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download