newbie
newbie

Reputation: 227

Jquery radio button selector

Hi I have the following JSON file

{
"bazar":
                   {"display_name":"BazaAR:",
                    "name":"bazaar",
                    "format":"string",
                    "type":"checkbox",
                    "format":"string",
                    "dflt":"MarkerBased",
                    "values":["MarkerBased","MarkerLess"],
                    "isMandatory":"true"
                    },


"face_detection":  
                   { "display_name":"Face Detection:",
                     "name":"face",
                     "format":"string",
                     "type":"checkbox",
                     "dflt":"No",
                     "values":["Yes","No"],
                     "isMandatory":"true"
                    },


"motion_detection":                       
                   { "display_name":"Motion Detection:",
                     "name":"motion",
                     "format":"string",
                     "type":"checkbox",
                     "dflt":"No",
                     "values":["Yes","No"],
                     "isMandatory":"true"
                    }
}

Now I am generating the tags in my js file using getJSON()

$.getJSON('json_input/server_settings_input.json',function(serverData)
{
$.each(serverData,function(feild)
        {
            if(this.type=="checkbox")
            {                           
                $('body #tabs #tabs-3 #server').append(this.display_name).append(INPUT_CHECKBOX).attr({name:this.name}).append(NEWLINE);
            }       
            else
                if(this.type=="radiobutton")
                {                           
                    $('body #tabs #tabs-3 #server').append(this.display_name).append(INPUT_RADIO).attr({name:this.name}).append(NEWLINE);
                }
        });

$('body #tabs #tabs-3 #server').append(SUBMIT_BUTTON);

});

How do I do the radio button check?? I tried with attr("checked":"checked")but its not working.I want to have a generic function which will check for radio buttons.How do I go about it

Upvotes: 0

Views: 422

Answers (3)

4b0
4b0

Reputation: 22323

try this:
$("input[Attrname='radio_name']:checked");

Upvotes: 0

frictionlesspulley
frictionlesspulley

Reputation: 12368

If you are using JQuery 1.6 >

use

 .attr('checked',true)

Upvotes: 2

DavidWainwright
DavidWainwright

Reputation: 2935

Shouldn't it be

.attr("checked", "checked")

?

Upvotes: 0

Related Questions