hii every one,
i have an application containing data list.
datalist contains radio button as item template.i want only one radio button to be checked ie when the user clicks on one checkbox the other checkboxes should be unchecked.i have used groupname ,but no use .can any one give the solution to this problem.

Recommended Answers

All 3 Replies

well, you can use checkboxlist but it doesn't work like radio buttons do. The user will be able to select multiple ones if you choose checkboxes instead of radio buttons. But if you decide to do checkboxes, use javascript to uncheck the other boxes in your group.

<script type="text/javascript">
function selectChkBox(field,checkit)
{
  for (i = 0; i < field.length; i++) {
	field[i].checked = false;
  }
  checkit.checked = true;
}
</script>

then call it with an OnClick event like below:

<label><input type="checkbox" id="chkSelection" name="checkbox3" value="3" onclick="javascript:selectChkBox(document.formname.chkSelection,this.name)" />Checkbox 3</label>

I haven't tested it, but it should work. What it does is set all the checkboxes to unchecked, then checks the corresponding checkbox found by its name. Make sure that all your checkboxes are one ID (that are affected anyway), and then have each one a different name.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.