Jquery gets the selected radio button from the list on the download page

I was wondering if anyone could post an example of how to get the selected switch option from the list of items in the asp.net switch list through jquery when the page loads.

thanks

+5
source share
3 answers

In your javascript function where you want to request a list, use this code.

var selected = jQuery('#<%= MyRadioButtonList.ClientID %> input:checked').val();
// or ...
var selected = $('#<%= MyRadioButtonList.ClientID %> input:checked').val();

to set a sample label with the results of your selected radio book, you can do this ...

$(document).ready(function(){
    var selected = $('#<%= MyRadioButtonList.ClientID %> input:checked').val();
    $("#<%= MySampleLabel.ClientID %>").text(selected);
}
+5
source

A working example is here .

, , ofinterest .

$(function(){ 
  var value = $('input.ofinterest:checked').val();
  $('#result').text(value); 
});

, JS aspx/ascx, Scott. , , JS .js.

+1
protected void radioButton_CheckedChanged(object sender, EventArgs e)
{
  throw new ApplicationException("Radio Changed");
  RadioButton rb = (RadioButton)sender;
  TextBox tbexact = (TextBox)this.UpdatePanel1.FindControl("TextBoxExact");
  TextBox tbpartial = (TextBox)this.UpdatePanel1.FindControl("TextBoxPartial");
  DropDownList dropdown = (DropDownList)this.UpdatePanel1.FindControl("DropDownListCountries");

  RadioButton rbc = (RadioButton)this.UpdatePanel1.FindControl("RadioButtonExact");
  if (tbexact == null)
    throw new ApplicationException("Could not find control");
  else
    throw new ApplicationException("Found it");
  if (rbc != null && rb.Equals(rbc))
  {
    tbpartial.Enabled = false;
    dropdown.Enabled = false;
    mCriteria = SearchCriteria.Exact;
  }
  rbc = (RadioButton)this.UpdatePanel1.FindControl("RadioButtonPartial");
  if (rbc != null && rb.Equals(rbc))
  {
    tbexact.Enabled = false;
    dropdown.Enabled = false;
    mCriteria = SearchCriteria.Partial;
  }
  rbc = (RadioButton)this.UpdatePanel1.FindControl("RadioButtonPerCountry");
  if (rbc != null && rb.Equals(rbc))
  {
    tbexact.Enabled = false;
    tbpartial.Enabled = false;
    mCriteria = SearchCriteria.Country;
  }
}
+1
source

All Articles