Reputation: 487
Here is jquery script used to select radio button.
function radio(){
var presetValue = "scholar";
$("[name=identity]").filter("[value="+presetValue+"]").attr("checked","checked");
}
The scrip is invoked on page load. This is XHTML peace of code:
<label for="scholar"> Scholar </label>
<input type="radio" name="identity" id="scholar" value="scholar" />
</td>
<td>
<label for="oracle"> Oracle </label>
<input type="radio" name="identity" id="oracle" value="oracle"/>
</td>
<td>
<label for="both"> Both </label>
<input type="radio" name="identity" id="both" value="both"/>
When the program runs that 'scholar' radio button is not selected. What might be the problem? Best regards
Upvotes: 0
Views: 528
Reputation: 22210
If you're using jQuery >= 1.6, you should use prop()
.
Also, you're using a complicated selector for nothing. Since your inputs have id's, this will do it:
$('#scholar').prop('checked', true);
If presetValue
changes (i.e: you simplified the code), do this:
$('#' + presetValue).prop('checked', true);
Upvotes: 1
Reputation: 5905
function radio(){
var presetValue = "scholar";
$("input[value="+presetValue+"]").attr("checked",true);
}
Upvotes: 0
Reputation: 5685
Check out this answer: how to set radio option checked onload with jQuery
Upvotes: 0