http://i198.photobucket.com/albums/aa158/runningstyle/02/ly.jpg?t=1240109941
how do i go about writing a code to display the answer in a label?

Dani AI

Generated

The screenshot shows a small group of selectable options and a label where the selected value should appear. As asked and as pointed toward, the general pattern is: watch for the control's change event and update the label text. Below are two concise, practical approaches depending on whether this is a browser UI or a .NET desktop form.

HTML + JavaScript (client-side)

<fieldset id="opts">
  <label><input type="checkbox" value="A"> A</label>
  <label><input type="checkbox" value="B"> B</label>
  <label><input type="checkbox" value="C"> C</label>
</fieldset>
<div id="display">None selected</div>

<script>
document.getElementById('opts').addEventListener('change', function(){
  var selected = Array.from(this.querySelectorAll('input[type=checkbox]:checked'))
                      .map(function(i){ return i.value; });
  document.getElementById('display').textContent = selected.length ? selected.join(', ') : 'None selected';
});
</script>

Windows Forms (C#)

private void Option_CheckedChanged(object sender, EventArgs e)
{
    var rb = sender as RadioButton;
    if (rb != null && rb.Checked)
        labelResult.Text = rb.Text;
}

private void CheckBox_CheckedChanged(object sender, EventArgs e)
{
    var items = groupBox1.Controls.OfType<CheckBox>()
                 .Where(cb => cb.Checked)
                 .Select(cb => cb.Text);
    labelResult.Text = string.Join(", ", items);
}

Quick troubleshooting and tips:

  • Ensure events are wired (designer or code) and run the same handler for all group controls when convenient.
  • For HTML radios, use the same name to make them mutually exclusive; for WinForms, place radio buttons inside the same container.
  • Update the label on load to reflect any initial selection.
  • For web apps, prefer client-side updates for instant feedback; use server-side postbacks only when needed.

You can use the CheckedChanged event of the radio button, then set the Text property of the text box.

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.