0
<select class="form-control"> <option>Loader</option> <option>Shopper</option> </select> 

I need it to disable this whole select class once I selected an option. Like the user can't select again once he/she selected once. Thank you!!

3 Answers 3

2

Simply use onchange property:

<select class="form-control" id="select" onchange="this.disabled=true;"> <option>Loader</option> <option>Shopper</option> </select>

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

Comments

2

you can do it on the onchange event just like below:

 <select class="form-control" id="select"> <option>Loader</option> <option>Shopper</option> </select> <script> $('#select').on('change', function() { $(this).attr('disabled', 'disabled') }); <script> 

this is the same code as @flint but for this to work you have define the jquery either from CDN(online url) or you can download the jquery and put it in your page in script tag.

Comments

1

This isn't a task for PHP. You'll need to use javascript and jquery would make it even easier.

<select class="form-control" id="select"> <option>Loader</option> <option>Shopper</option> </select> <script> $('#select').on('change', function() { $(this).attr('disabled', 'disabled') }); <script> 

3 Comments

it's not working.. the select class is not turning off(or disabled) once selected:(((
@AngelaVillamar have you added id="select" as stated in this answer? Because the jQuery snippet is targetting via id, it will not work unless the id matches
BTW simply saying its not working isn't helpful, tell us what errors you recieved. since its JavaScript, they'll be visible in browser's Dev Tools console. Press f12 then locate console.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.