JavaScript Check a radio button with data from JSON check radio button jquery,check radio button javascript,check radio

I have the following radio buttons :

<td valign="top">
    <label>Have you ever been tested?</label>

    <input required id="Test" name="Test" type="radio" class="wellness_center radiostyle" value="1">
    <div class="radiolabel">Yes</div>
    <input required id="Test" name="Test" type="radio" class="wellness_center radiostyle" value="0">
    <div class="radiolabel">No</div>
</td>

Which submits data to the database in the form of 0 and 1 (1=Yes,0=No). I would like to pull this information from the database and re-map/highlight back the radio button based on the value that was saved in the database. I tried the following method :

$.ajax({
    type: "GET",
    url: "database/Emarps/websrvc/websrvc.php?task=getData&UUID=" + currentuuid + "&DataGt=hk",
    dataType: "JSON",
    success: function (response) {
        $.each(response, function (i, resp) {

            if (resp.tested === $("input[name='Test'][value='1']").prop('checked', true)) {

            } else if (resp.tested === $("input[name='Test'][value='0']").prop('checked', true)) {

            }

        });
    }
});

Which retrieves the data very well from the database but it fails to map it to the respective radio buttons. Please assist , how can I map it back to the right radio base on values from Database passed through JSON?

Answer:1

To compare, you may simply use literal:

if (resp.tested === "1") {
  $("input[name='Test'][value='1']").prop('checked', true);
}

You may try this instead:

$("input[name=Test]").prop('checked', false); //uncheck all
$.each(response, function (i, resp) {
  $("input[name=Test][value=" + resp.tested + "]").prop('checked', true);
}
Answer:2

I'm trying to open automatically a drop downdown menu when I hit the "Tab" key on the keyboard and focus my element.The focus function works, but the trigger doesn't. My intention is to force the "...

I'm trying to open automatically a drop downdown menu when I hit the "Tab" key on the keyboard and focus my element.The focus function works, but the trigger doesn't. My intention is to force the "...

  1. open dropdown select jquery
  2. open select dropdown on button click javascript
  3. open select dropdown on button click
  4. open select dropdown on button click jquery
  5. open select dropdown javascript
  6. open select dropdown on hover
  7. open select dropdown
  8. open select dropdown on click
  9. open select dropdown on enter
  10. open select dropdown using jquery
  11. open select dropdown programmatically
  12. open select dropdown on button click angular 6
  13. open select dropdown css
  14. openoffice drop down select
  15. open popup on dropdown select
  16. javascript open select dropdown programmatically
  17. js open select dropdown
  18. open modal on dropdown select
  19. html open select dropdown
  20. onclick open select dropdown

I don't understand why the request for button does not performed. I must to change the direction for mobile screens, but until it's now work. $( "button.btn-tooltip" ).attr( "data-placement", "...

I don't understand why the request for button does not performed. I must to change the direction for mobile screens, but until it's now work. $( "button.btn-tooltip" ).attr( "data-placement", "...

  1. canvas
  2. canada
  3. cancelled
  4. canceled vs cancelled
  5. cancun
  6. canada goose
  7. cane corso
  8. canes
  9. canadian prime minister
  10. cancun flights
  11. canker sore
  12. candy
  13. cancer
  14. canon
  15. canvas prints
  16. cancer sign
  17. candace owens
  18. canada news
  19. candytopia
  20. canlis

I want to create a customized scrollbar with pure CSS3 and JS. This should be done using div elements. Please avoid plugins and overflow-scroll. The content div may contain any element like p, ul or ...

I want to create a customized scrollbar with pure CSS3 and JS. This should be done using div elements. Please avoid plugins and overflow-scroll. The content div may contain any element like p, ul or ...

  1. custom scrollbar using css
  2. custom scrollbar using javascript
  3. custom scrollbar using jquery
  4. custom scrollbar using css for firefox
  5. custom scrollbar using css for all browsers
  6. custom scrollbar using css only
  7. custom scrollbar using css for ie
  8. custom scrollbar using angularjs
  9. custom scrollbar using bootstrap
  10. custom scrollbar using css codepen
  11. custom scrollbar using angular
  12. custom scrollbar in firefox
  13. custom scrollbar in css
  14. custom scrollbar in ie
  15. custom scrollbar in div
  16. custom scrollbar in angular 6
  17. custom scrollbar with arrows
  18. custom scrollbar in mozilla
  19. custom scrollbar in react
  20. custom scrollbar in div css

I have a web page that creates a list of contacts and their email addresses. You have two options for the mailto link, (1) open it in the current window or (2) open it in a new tab/window. I see ...

I have a web page that creates a list of contacts and their email addresses. You have two options for the mailto link, (1) open it in the current window or (2) open it in a new tab/window. I see ...

  1. mailto link open in gmail
  2. mailto link open outlook
  3. mailto link open in new tab
  4. mailto link open owa
  5. mailto link open chrome
  6. mailto link open browser
  7. mailto links open in chrome instead of outlook
  8. mailto link doesn't open outlook
  9. click mailto link open outlook
  10. mailto link doesn't open outlook 2016
  11. mailto link won't open outlook
  12. outlook mailto links open in chrome
  13. mailto javascript open link
  14. open mailto link
  15. how to make mailto link open in outlook
  16. open mailto link jquery
  17. open mailto link in yahoo