Not able to set default value for radio type and selector

snisnik

New Member
i have checked this link Set radio button 'checked' in jquery based on ID However, seems not very suitable for me. This is my code\[code\] <label for="basic" class="basic">Gender:</label> <fieldset data-type="horizontal" data-role="controlgroup" data-mini="true"> <input type="radio" name="gender" id="radio-mini-1" value="http://stackoverflow.com/questions/15581109/Male" checked="checked" /> <label for="radio-mini-1">Male</label> <input type="radio" name="gender" id="radio-mini-3" value="http://stackoverflow.com/questions/15581109/Female" /> <label for="radio-mini-3">Female</label> </fieldset>\[/code\]and\[code\] <label for="select-choice-min" class="select">Living Place:</label> <select name="select-choice-min" id="livingPlace" data-mini="true"> <optgroup label="AAA"> <option value="http://stackoverflow.com/questions/15581109/123">123</option> <option value="http://stackoverflow.com/questions/15581109/456">456</option> </optgroup> <optgroup label="BBB"> <option value="http://stackoverflow.com/questions/15581109/789">789</option> <option value="http://stackoverflow.com/questions/15581109/246">246</option> </optgroup> </select>\[/code\]can i simply use the following code to set default value? seems not work\[code\] $("#livingPlace :selected").text(data[0].data.livingPlace); //$('#livingPlace option[value=http://stackoverflow.com/questions/15581109/data[0].data.livingPlace]').attr("selected",true); $("input[name=gender]:checked").val(data[0].data.gender);\[/code\]i have also tried \[code\]$('input[name=gender][value="' + data[0].data.gender + '"]').prop('checked', true);\[/code\]but also not work for memay I ask how to set the default value ? thanksmy json return is something like this\[code\][{"data":{"id":"8","livingPlace":"789","gender":"Female"}}]\[/code\]
 
Back
Top