JavaScript Radio button checked attribute is not getting set to false radio button checked by default,radio button checked html,radio

I have 2 buttons yes and no, and simply I am toggling them.

<!DOCTYPE html>
   <html>
      <head>
         <title>Demo Project</title>
      </head>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
      <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
      <script src=""></script>
      <script>  
          function enableCheckBoxAndDisableNoRadioButton() {
             $(".checkbox").attr("checked",true);
             $("#no").attr("checked", false);
          }

          function disableCheckBoxAnddisableYesRadioButton() {
             $("#yes").attr("checked", false);
             $(".checkbox").attr("checked",false);
          }
      </script>
      <body>
         <input class="checkbox" type="checkbox" >
         <p>yes <input id="yes" type="radio" onchange="enableCheckBoxAndDisableNoRadioButton()"></p>
         <p> no<input id="no" type="radio" checked=true onchange="disableCheckBoxAnddisableYesRadioButton()"></p>
      </body>
   </html>

When I click at yes, that time no button getting deselected and checkbox getting selected. But when I click at the no button, that time checkbox getting deselected but yes button is selected too. I want to make it deselect.

Let me know what is the problem.

I am running this code on chrome: 53.0.

Answer:1

Use prop insted of attr.

function enableCheckBoxAndDisableNoRadioButton() {
    $(".checkbox").prop("checked", true);
    $("#no").prop("checked", false);
  }

  function disableCheckBoxAnddisableYesRadioButton() {
    $("#yes").prop("checked", false);
    $(".checkbox").prop("checked", false);

  }

Working Fiddle

Answer:2

in place of attr, i changed it to .prop and it is working now.

Answer:3

change .attr to .prop then it worked

Answer:4

I have a trie (also called a prefix tree). Given a prefix, I want to get a list of ten words that start with the prefix. The thing that's unique about this problem is that I only want 10 of the ...

I have a trie (also called a prefix tree). Given a prefix, I want to get a list of ten words that start with the prefix. The thing that's unique about this problem is that I only want 10 of the ...

I'm trying to get data from a server in my AngularJS app, using $http.get. But when I execute the request, it seems to get cancelled by something. It happens with every link I use. Local files are ...

I'm trying to get data from a server in my AngularJS app, using $http.get. But when I execute the request, it seems to get cancelled by something. It happens with every link I use. Local files are ...

  1. angularjs http request
  2. angularjs http request example
  3. angularjs http request timeout
  4. angularjs http request default timeout
  5. angularjs http request headers
  6. angularjs http request in loop
  7. angularjs http request interceptor example
  8. angularjs http request interceptor
  9. angularjs http request progress bar
  10. angularjs http request error handling
  11. angularjs http request synchronous
  12. angularjs http request parameters
  13. angularjs http request cors
  14. angularjs http request body
  15. angularjs http request json
  16. angularjs http request multipart/form-data
  17. angularjs http request cross domain
  18. angularjs http request method options
  19. angularjs http request content type
  20. angularjs http request form data

So I can create a whole bunch of empty objects that are independent with my code below. Is there a better way to do this? Or is this the only method? var array = []; for (let i = 0; i < 5; ...

So I can create a whole bunch of empty objects that are independent with my code below. Is there a better way to do this? Or is this the only method? var array = []; for (let i = 0; i < 5; ...

Here is my setup. I have a grunt task that does 2 things: 1) start a http server listening on some port 2) triggers another grunt task The grunt task triggered above is a testem task that runs tests ...

Here is my setup. I have a grunt task that does 2 things: 1) start a http server listening on some port 2) triggers another grunt task The grunt task triggered above is a testem task that runs tests ...

  1. post call from browser
  2. post call from javascript
  3. post call from java
  4. post call from postman
  5. post call from angular
  6. post call from python
  7. post call from c#
  8. post call from react
  9. post call from jquery
  10. post call from php
  11. post call from curl
  12. post call from html
  13. post call from node js
  14. post call from js
  15. post call in react js
  16. post call from angular 7
  17. post call from ajax
  18. post call from react js
  19. post call from angularjs
  20. post call in angular 6