2

I want to do that when some one select the option one then 1st input is enabled using jQuery

here is the sample code:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="form-material">
  <label for="storeCategory">Store Details</label>

  <select class="form-control" id="storeABDetails">
    <option value="message">Message</option>
    <option value="image">Image</option>
    <option value="video">Video</option>
  </select>

</div>

<div class="form-group">
  <div class="col-sm-8 col-sm-offset-2">
    <div class="form-material">
      <input type="text" class="form-control" id="shortMessage" name="shortMessage" placeholder="Please enter the short message" >
      <label for="shortMessage">Short Message</label>
    </div>
  </div>
</div>

<div class="form-group">
  <div class="col-sm-8 col-sm-offset-2">
    <div class="form-material">
      <input type="file" id="image" name="storeImage">
      <label for="storeImage">Store Image</label>
    </div>
  </div>
</div>

<div class="form-group">
  <div class="col-sm-8 col-sm-offset-2">
    <div class="form-material">
      <input type="file" id="video" name="storeVideo">
      <label for="storeVideo">Store Video</label>
    </div>
  </div>
</div>

If message is selection the message input is enabled and when image and video is selection then image and video selection enabled and disabled.

I want the jquery how to do that please help me out

1 Answer 1

1
  1. You need to use change() event to detect when the select was changed.
  2. I was changed the value of Message to shortMessage so it will easier to get the value and find the right input.
  3. Use .prop function to enable\disable the inputs.

var ddl = $('#storeABDetails').change(function() {
  var val = ddl.val();
  
  $('.form-material input').prop('disabled', true);
  $('#' + val).prop('disabled', false);
});

ddl.trigger('change')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="form-material">
  <label for="storeCategory">Store Details</label>

  <select class="form-control" id="storeABDetails">
    <option value="shortMessage">Message</option>
    <option value="image">Image</option>
    <option value="video">Video</option>
  </select>

</div>

<div class="form-group">
  <div class="col-sm-8 col-sm-offset-2">
    <div class="form-material">
      <input type="text" class="form-control" id="shortMessage" name="shortMessage" placeholder="Please enter the short message" >
      <label for="shortMessage">Short Message</label>
    </div>
  </div>
</div>
<div class="form-group">
  <div class="col-sm-8 col-sm-offset-2">
    <div class="form-material">
      <input type="file" id="image" name="storeImage">
      <label for="storeImage">Store Image</label>
    </div>
  </div>
</div>

<div class="form-group">
  <div class="col-sm-8 col-sm-offset-2">
    <div class="form-material">
      <input type="file" id="video" name="storeVideo">
      <label for="storeVideo">Store Video</label>
    </div>
  </div>
</div>

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

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.