Jump to content
Sign in to follow this  

select and disable for dropdown

Recommended Posts


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> 
            <input type="submit" value = "Submit">
        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) {
                    if (proCount > promaxOptions) {
                        alert("Already 5 variables selected")
                        return false;
            return true;

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

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...