JavaScript Way to lock a select element after a radio button is selected in jQuery

Add the attribute disabled to the select element upon the radio input changing states. And remove the disabled attribut upon form submission, allowing the input to be sent.

$('#radios input').change(function(){
  $('#drop_down').prop('disabled', true);
});

$('form').on('submit', function() {
    $(this).find('#drop_down').removeAttr('disabled');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<form action="" method="post">

    <select id="drop_down">
      <option value="1">One</option>
      <option value="2">Two</option>
      <option value="3">Three</option>
      <option value="4">Four</option>
    </select>
    
    <div id="radios">
      <input type="radio" value="blue" id="blue" name="radio_option">Blue</input>
      <input type="radio" value="green" id="blue" name="radio_option">Green</input>
    </div>

    <button type="submit">Submit</button>

</form>    
Answer:1

You can set the button to be disabled, and update a hidden field to use the selected option, so that it also passes when you post the form.

EDIT (adding the code)

The HTML (notice the last input still within the form):

<select id="drop_down">
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
  <option value="4">Four</option>
</select>
<form id="radios">
  <input type="radio" value="blue" id="blue" name="radio_option" class="radios">Blue</input>
  <input type="radio" value="green" id="green" name="radio_option" class="radios">Green</input>
  <input type="hidden" id="myvalue" name="radio_option" />
</form>

The jQuery code (notice I'm giving a class to the radios above, and am using that in js, so that when I do the disabling, the hidden input doesn't get disabled):

$('.radios').change(function() {
  $(this).attr('disabled', true);
  $('#myvalue').val($(this).val());
}
Answer:2

I have an object similar to this: $scope.division = [ { name: "Tom", number: 1 }, { name: "Greg", number: 2 } ]; Now in my HTML I'm using ngOption to display a drop down ...

I have an object similar to this: $scope.division = [ { name: "Tom", number: 1 }, { name: "Greg", number: 2 } ]; Now in my HTML I'm using ngOption to display a drop down ...

I wish to have a row of 3 images which will contain around 10 images per row. The image dimensions are 270x270px and should animate like you'd imagine clouds floating from right to left on the screen....

I wish to have a row of 3 images which will contain around 10 images per row. The image dimensions are 270x270px and should animate like you'd imagine clouds floating from right to left on the screen....

We are trying to test our controller with Karma, but Karma keeps complaining about an unknown provider: Error: [$injector:unpr] Unknown provider: userProvider <- user Are we injecting the user ...

We are trying to test our controller with Karma, but Karma keeps complaining about an unknown provider: Error: [$injector:unpr] Unknown provider: userProvider <- user Are we injecting the user ...

  1. karma error spawn unknown
  2. karma-server error spawn unknown

Arrays in a language like C have certain non-functional characteristics, like O(n) insertion and deletion. But C operates on the bare metal, allocating contiguous bytes of memory. In JavaScript, ...

Arrays in a language like C have certain non-functional characteristics, like O(n) insertion and deletion. But C operates on the bare metal, allocating contiguous bytes of memory. In JavaScript, ...