1

How can i disable a select_tag like this example with javascript :

<button onclick="DisableFields()">Disable</button>  

<p class="col-lg-2" id ="test1" >
   <%= 
      select_tag(:customer_service_beneficiary_id,  options_for_select(customer_service_beneficiary_col) , :class => "form-control")
   %>
</p>

I try this but it doesnt work :

function DisableFields() {
  console.log('Disable');
  $("test1").prop('disabled', true);
  $("test2").attr('disabled','disabled');
}
4
  • add this man :disabled=>true Commented Apr 11, 2016 at 8:12
  • you are selection is wrong test1 is for div not for the select tag Commented Apr 11, 2016 at 8:15
  • 1
    try $("select[name="name-of -select"]").attr("disabled","disabled") @Krebsmann Commented Apr 11, 2016 at 8:17
  • @uzaif you are right. Krebsmann, Can you show us the output code (not ruby tag? Commented Apr 11, 2016 at 8:17

2 Answers 2

2

try this You are not selecting div not select

$('select[name="name-of-select"]').attr("disabled","disabled")
Sign up to request clarification or add additional context in comments.

Comments

1

You can disable this by the name of the select field as @uzaif said :

$("select[name='select-field-name']").attr("disabled","disabled")

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.