1

i want to stop the user to see the list while clicking select option element :

<select name="_users_id_requester">
  <option value="0">-----</option>
  <option selected="" value="774">Asmaa El Habib,Yassine</option>//except this one 
  <option value="779" title="Ahlam Edouiri - U8K8O">Ahlam Edouiri</option>
  <option value="746" title="Ainane Mohamed - MohamedAinane">Ainane Mohamed</option>
</select>

i have tried the readonly method , but the problem is i'm using the element within a form , so the form can't read the selected value

1 Answer 1

1

Start by giving the select an id. Perhaps

<select name="_users_id_requester" id "requestor" class = "requestorList">
   <option value="0">-----</option>
   <option selected="" value="774">Asmaa El Habib,Yassine</option>//except this one 
   <option value="779" title="Ahlam Edouiri - U8K8O">Ahlam Edouiri</option>
   <option value="746" title="Ainane Mohamed - MohamedAinane">Ainane Mohamed</option>
</select>

Then you can easily disable the control

$('#requestor').prop('disabled', 'disabled');

To reenable the control:

$('#requestor').prop('disabled', '');

If you can't set the ID:

$('.requestorList').prop('disabled', 'disabled');

To reenable the control:

$('.requestorList').prop('disabled', '');
5
  • 1
    Disabled is a property, not an attribute. You should use prop() instead. Feb 25, 2013 at 23:27
  • i'm using an existing openSource solution called GLPI , they re using MVC method , and the id are genereted automatically always with defrent value, so just how can i get the element id value using jquery ? Feb 25, 2013 at 23:28
  • 1
    If you do not have control over the IDs generated, you can use alternate selector options. Such as css class or other attributes. I will update the answer to show this option and incorporate Alien Webguy's point. Feb 25, 2013 at 23:34
  • the form steel can't read the POST name of the diseabled attr , any another solution ? Feb 26, 2013 at 3:02
  • how are you trying to get the value? Feb 26, 2013 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.