Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3697566
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:52:32+00:00 2026-05-19T04:52:32+00:00

I have 2 radio groups in a modal form.. I am having a difficult

  • 0

I have 2 radio groups in a modal form.. I am having a difficult time figuring out how to set the value for each group from a json string.. The last 2 values in the json string is "role" and "activated". Activate is either 1 for Yes or 0 for now. Role is either 1, 2 or 3 for Admin, Staff or User. I loop thru the json string and assign the values to field names since they are all identical in the html.

My html is:

<div class="form-field bt-space10">
    <div class="clear">
    <h4 class="fl-space2 ln-22 size-120" style="color:#777777; font-size: 12px; font-weight: normal;">Authorization Role: </h4>
                                
    <div class="form-radio-item clear fl-space2">
        <input type="radio" rel="radiogroup" name="role" id="Admin" value="1" class="radio fl-space" /> <label for="Admin" class="fl">Admin</label>
    </div>
    
    <div class="form-radio-item clear fl-space2">
        <input type="radio" rel="radiogroup" name="role" id="Staff" value="2" class="radio fl-space" /> <label for="Staff" class="fl">Staff</label>
    </div>  
    
    <div class="form-radio-item clear fl-space2">
        <input type="radio" rel="radiogroup" name="role" id="User" value="3" class="radio fl-space" /> <label for="User" class="fl">User</label>
    </div>
    </div>
    <div class="clear">
    <h4 class="fl-space2 ln-22 size-120" style="color:#777777; font-size: 12px; font-weight: normal;">Account Activated: </h4>
                                
    <div class="form-radio-item clear fl-space2">
        <input type="radio" rel="radiogroup1" name="activated" id="Yes" class="radio fl-space" /> <label for="radio4" class="fl">Yes</label>
    </div>
    
    <div class="form-radio-item clear fl-space2">
        <input type="radio" rel="radiogroup1" name="activated" id="No" class="radio fl-space" /> <label for="radio5" class="fl">No</label>
    </div>  
    </div>  
        
</div><!-- /.form-field-->

My incoming json string (if needed, I could change the return to "Role":"Admin", etc.. and "activated":"Yes", etc.):

{"op": "UPDATE", "id": "7","email": "joe@public.com","name": "Joe Public","address": "123 Any Street","city": "AnyTown","zipcode": "12345","state": "PA","contact_name": "","phone": "8885551212","fax": "","company_branch": "","company_name": "","activated": "1","role": "1" }

The code I use to populate other fields on the form:

function editUser(rowID, callback) {
    var ret;
    jQuery.fancybox({
        modal : true,
        padding : 0,
        cache : false,
        overlayOpacity : 0.5,
        href : "userEdit.html",
        onComplete : function() {
            InitProfileMenu()
            var tsTimeStamp= new Date().getTime();
            $.getJSON("includes/GetUserDetails.php?tsTimeStamp&id=" + rowID,     
                function(data) {
                    $.each(data, function(i, item) {
                    $('#' + i).val(item);
                });
            })
            jQuery("#editUser_cancel").click(function() {
                ret = false;
                jQuery.fancybox.close();
            })
            jQuery("#editUser_ok").click(function() {
                jQuery.fancybox.close();
                ret = true;
            })
        },

I have Googled this to death and not finding a solution. Anyone have any ideas? or a resource they can point me to which would help figure this out?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:52:32+00:00Added an answer on May 19, 2026 at 4:52 am

    This is difficult to resolve in a generic way for all values in your JSON string because the html attribues are not like one another. I suggest two changes:

    1. Add a value attribute to the radio inputs named “activated”
    2. For each element of JSON data: check the type of form input, if radio, use name and value attribute selectors to check the correct one.

       var myJsonData = {
          "op": "UPDATE",
           "id": "7",
          "email": "joe@public.com",
          "name": "Dennis Megarry",
          "address": "123 Any Street",
          "city": "AnyTown",
          "zipcode": "12345",
          "state": "PA",
          "contact_name": "",
          "phone": "8885551212",
          "fax": "",
          "company_branch": "",
          "company_name": "",
          "activated": "1",
          "role": "1"
      };
      
      function updateFormWithJson(dataObj) {
          $.each(dataObj,function(i,item){
              if($('input[name="' + i + '"]:first').attr("type") == "radio"){
                  $('input[name="' + i + '"][value="' + item + '"]').attr("checked","checked");
              }
          });
      };
      
      $(document).ready(function() {
          updateFormWithJson(myJsonData);
      });
      
      <div class="form-field bt-space10">
          <div class="clear">
          <h4 class="fl-space2 ln-22 size-120" style="color:#777777; font-size: 12px; font-weight: normal;">Authorization Role: </h4>
      
          <div class="form-radio-item clear fl-space2">
              <input type="radio" rel="radiogroup" name="role" id="Admin" value="1" class="radio fl-space" /> <label for="Admin" class="fl">Admin</label>
          </div>
      
          <div class="form-radio-item clear fl-space2">
              <input type="radio" rel="radiogroup" name="role" id="Staff" value="2" class="radio fl-space" /> <label for="Staff" class="fl">Staff</label>
          </div>  
      
          <div class="form-radio-item clear fl-space2">
              <input type="radio" rel="radiogroup" name="role" id="User" value="3" class="radio fl-space" /> <label for="User" class="fl">User</label>
          </div>
          </div>
          <div class="clear">
          <h4 class="fl-space2 ln-22 size-120" style="color:#777777; font-size: 12px; font-weight: normal;">Account Activated: </h4>
      
          <div class="form-radio-item clear fl-space2">
              <input type="radio" rel="radiogroup1" name="activated" id="Yes" value="1" class="radio fl-space" /> <label for="radio4" class="fl">Yes</label>
          </div>
      
          <div class="form-radio-item clear fl-space2">
              <input type="radio" rel="radiogroup1" name="activated" id="No" value="0" class="radio fl-space" /> <label for="radio5" class="fl">No</label>
          </div>  
      </div>  
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having an incredibly difficult time to decorate a Zend form the way
i have one group of radiobutton: <div id=id1> <input id=pack1 type=radio class=pack name=pack value=OK
I have a depended radio groups, where by clicking on input#radio10, input#radio16 .form-block-cms should
I have a radio button on my Windows Form. How can I determine if
I've got a form where I have two radio buttons and two interchangeable controls
I have a set of radio buttons where a selection is required. In addition,
I have a form with some radio buttons that are disabled by default. When
I have a swing application that includes radio buttons on a form. I have
I have a mvc view made up of a matrix of radio buttons. Each
I have two radio button groups in my partial view and based on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.