Jump to content

select and disable for dropdown


rizwansyed

Recommended Posts

Hi

I need a multiple selection of drop down list  with select and disabled option for 3 elements.

Because 3 elements should be default selected and user should not able to deselect it.

<form action="/action_page.php" method="post" onclick="validate()"> 
            <select multiple="multiple" id="variable" name="variable"> 
                <option value="0" selected disabled>class1</option> 
                <option value="1" selected disabled>class2</option> 
                <option value="2" selected disabled>class3</option> 
                <option value="3">class4</option> 
                <option value="4">class5</option> 
                <option value="5">class6</option> 
                <option value="6">class7</option> 
                
            </select>
            <input type="submit" value = "Submit">
        </form>
        <script>
        function validate()
        {
            var selectpro = document.getElementById('variable');
            var promaxOptions = 5;
            var proCount = 0;
            for (var i = 0; i < selectpro.length; i++) {
                if (selectpro[i].selected) {
                    proCount++;
                    if (proCount > promaxOptions) {
                        alert("Already 5 variables selected")
                        return false;
                    }
                }
            }
            return true;
        }
        </script>

When submit button is pressed , class1, class2 and class3 should be submitted along with other class elements.

How to work on this

Please provide  the suggestions

 

Thanks and Regards

Rizwan Syed

Edited by rizwansyed
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...