Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change the attribute of dynamically created html radio button in jquery?
    primarykey
    data
    text
    <p>I am trying to change the checked attribute of dynamically created html radio button in asp.net using jquery. I tried different methods but I am not able to change the attribute.</p> <p>My aspx page and code behind file is as follows,</p> <pre><code> &lt;%@ Page Title="" Language="C#" MasterPageFile="~/FormMaster.master" AutoEventWireup="true" CodeFile="ArabiaHRLetterSurveyForm.aspx.cs" Inherits="HRLetter_Arabia_ArabiaHRLetterSurveyForm" %&gt; &lt;asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"&gt; &lt;div class="latest" style="width: 98%; margin-removed 10px; margin-removed 10px"&gt; &lt;span class="corner-left"&gt;&lt;span class="corner-right"&gt; &lt;div class="actions"&gt; &lt;a href="#" class="status" id="lnkHistory" style="color: #fff"&gt;History&lt;/a&gt;&lt;/div&gt; HR Letter Survey Form &lt;/span&gt;&lt;/span&gt; &lt;/div&gt; &lt;div style="width: 98%; margin-removed 10px; margin-removed 10px;"&gt; &lt;div&gt; &lt;table cellpadding="0" cellspacing="0" width="100%" class="tableClass"&gt; &lt;tr class="trClass" align="right"&gt; &lt;th class="full" colspan="5"&gt; Header &lt;/th&gt; &lt;/tr&gt; &lt;tr class="trClass" style="width: 100%"&gt; &lt;td class="first" style="width: 20%"&gt; Request No &lt;/td&gt; &lt;td class="last" style="width: 80%"&gt; &lt;a href="#" class="status" id="lnkRequestNo" style="color: Blue" target="_blank"&gt; &lt;%=Request["requestid"]%&gt;&lt;/a&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="div_survey" runat="server" style="width: 98%; margin-left: 10px; margin-right: 10px;"&gt; &lt;/div&gt; &lt;div&gt; &lt;table align="center"&gt; &lt;tr&gt; &lt;td class="innerTd"&gt; &lt;a href="#" id="btnSubmit" runat="server" class="button-small" önserverclick="btnSubmit_Click"&gt; &lt;span class="corner-left-small"&gt;&lt;span class="corner-right-small"&gt;Submit&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;asp:HiddenField ID="hUserIdEncrypted" runat="server" /&gt; &lt;asp:HiddenField ID="hInitiatorUserId" runat="server" /&gt; &lt;asp:HiddenField ID="hSurveyId" runat="server" /&gt; &lt;script type="text/javascript"&gt; $("#lnkRequestNo").attr("href", "ArabiaHRLetterRequest.aspx?requestid=" + &lt;%=Request["requestid"]%&gt; +"&amp;userId= " + $("#&lt;%=hUserIdEncrypted.ClientID %&gt;").val()); $("#lnkHistory").fancybox({ 'width': 700, 'height': 400, 'autoScale': true, 'transitionIn': 'none', 'transitionOut': 'none', 'type': 'iframe' }); $("#lnkHistory").attr("href", "ArabiaHRLetterSurveyFormHistory.aspx?surveyid=" + $("#&lt;%=hSurveyId.ClientID %&gt;").val()); $("#&lt;%=btnSubmit.ClientID %&gt;").click(function(ev) { ev.preventDefault(); var id; var selected; $("#&lt;%=div_survey.ClientID %&gt; tr:not(:has(th))").each(function() { $(this).find("td").each(function() { var o = $(this); var firstCol = o.parent().children().first(); id = firstCol.text(); selected = "N/A"; firstCol.next().next().find("input").each(function() { if($(this).is("checked")) { if($(this).val() == "YES") selected = "YES"; else if($(this).val() == "NO") selected = "NO"; else if($(this).val() == "N/A") selected = "NA"; } }); firstCol.next().next().find("textarea").each(function() { selected = "TextArea"; }); }); alert(id); alert(selected); }); }); $("input").each(function() { $(this).click(function(ev) { alert($(this).val()); if($(this).val() == "YES") { $("input[value='YES']").attr('checked', true); $("input[value='NO']").attr('checked', false); $("input[value='N/A']").attr('checked', false); } else if($(this).val() == "NO") { $("input[value='YES']").attr('checked', false); $("input[value='NO']").attr('checked', true); $("input[value='N/A']").attr('checked', false); } else if($(this).val() == "N/A") { $("input[value='YES']").attr('checked', false); $("input[value='NO']").attr('checked', false); $("input[value='N/A']").attr('checked', true); } //$('#Yes').attr("checked",false).checkboxradio("refresh"); //$("input[type='radio']").attr("checked",true).checkboxradio("refresh"); //$('input[name="yes_no_na0"]').attr('checked', false); //$(this).next().attr('checked', false); //$(this).next().next().attr('checked', false); }); }); &lt;/script&gt; &lt;/asp:Content&gt; My code behind file is as follows, using System; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using GWC.ToolKits; using System.Data.Linq; using System.Linq; using System.Text; using System.Windows; public partial class HRLetter_Arabia_ArabiaHRLetterSurveyForm : System.Web.UI.Page { protected void Page_PreInit(object sender, EventArgs e) { } protected void Page_Init(object sender, EventArgs e) { } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { BindQuestions(); hInitiatorUserId.Value = EncryptDecrypt.EncryptDecrypt.GetDecryptedData(Request["userId"]); hUserIdEncrypted.Value = Request["userId"]; var m1 = Database.GetSurveyId(Request["requestId"]); hSurveyId.Value = m1.survey_id.ToString(); var m = Database.GetSurveyId(Request["requestid"]); } } private void BindQuestions() { StringBuilder surveytable = new StringBuilder(); var m = Database.GetQuestions(); if (m.Count &gt; 0) { surveytable.Append("&lt;table cellpadding='0' cellspacing='0' width='100%' class='tableClass'&gt;"); surveytable.Append("&lt;tr class='trClass' align='right'&gt;"); surveytable.Append("&lt;th class='full'&gt;Id&lt;/th&gt;&lt;th class='full'&gt;Questions&lt;/th&gt;&lt;th class='full'&gt;Answers&lt;/th&gt;"); surveytable.Append("&lt;/tr&gt;"); if (m.Count &gt; 0) { for (int i = 0; i &lt; m.Count; i++) { surveytable.Append("&lt;tr class='trClass' style='width:100%'&gt;"); surveytable.Append("&lt;td class='first' style='width:5%'&gt;" + m[i].question_id + "&lt;/td&gt;"); surveytable.Append("&lt;td class='first' style='width:60%'&gt;" + m[i].question_description + " &lt;/td&gt;"); if (m[i].question_type_id == 1) { surveytable.Append("&lt;td class='last' style='width:35%'&gt;"); surveytable.Append("&lt;input id=\"rdoYes" + i + "\" name=\"yes_no_na" + i + "\" value=\"YES\" checked=\"false\" type=\"radio\"&gt;YES&lt;/input&gt;"); surveytable.Append("&lt;input id=\"rdoNo" + i + "\" name=\"yes_no_na" + i + "\" value=\"NO\" checked=\"false\" type=\"radio\"&gt;NO&lt;/input&gt;"); surveytable.Append("&lt;input id=\"rdoNa" + i + "\" name=\"yes_no_na" + i + "\" value=\"N/A\" checked=\"true\" type=\"radio\"&gt;N/A&lt;/input&gt;"); surveytable.Append("&lt;/td&gt;"); } else { surveytable.Append("&lt;td class='last' style='width:35%'&gt;"); surveytable.Append("&lt;Textarea id=\"txtComment" + i + "\" type=\"text\" runat=\"server\" style='width:98%; height:100px'&gt;&lt;/Textarea&gt;"); surveytable.Append("&lt;/td&gt;"); } surveytable.Append("&lt;/tr&gt;"); } } surveytable.Append("&lt;/table&gt;"); div_survey.InnerHtml = surveytable.ToString(); } else { } } private void SendNotificationAll(string userId, string subject, string body, string cc, string bcc) { try { string approvalEmail; approvalEmail = EmployeeData.GetEmployeeEmailByUserId(userId); MailHelper mailHelper = new MailHelper(); Utilities util = new Utilities(); mailHelper.SendMailMessage(util.GetValueFromConfigFile("SupportEmail"), approvalEmail, bcc, cc, subject, body); } catch (Exception exp) { LogManager logHelper = new LogManager(Request.PhysicalApplicationPath.Trim(), "HR Letter Request"); logHelper.LogError("[SendApproverNotification - ]" + exp.Message); } } private void AlertMessage(string message) { string strScript; strScript = "&lt;script language=javascript&gt;alert('" + message + "');&lt;/script&gt;"; Page.RegisterClientScriptBlock("key", strScript); } protected void btnSubmit_Click(object sender, EventArgs e) { DateTime datetime1, datetime2; datetime1 = DateTime.Now; datetime2 = datetime1.AddSeconds(1); string request_no = Request["requestid"]; var m = Database.GetSurveyId(request_no); string survey_id = m.survey_id.ToString(); Database.UpdateHRLetterSurveyMasterData(request_no, "2"); Database.RegisterHRLetterSurveyHistory(survey_id, hInitiatorUserId.Value, datetime1.ToString(), "C", datetime2.ToString(), "Survey Completed"); string peoplelinkUserId = GeneralData.GetCountryPeoplelink("1"); Database.RegisterHRLetterHistory(request_no, peoplelinkUserId, datetime1.ToString(), "E", datetime2.ToString(), "Survey Completed"); string messageid; messageid = GeneralData.InsertMessage(request_no, peoplelinkUserId, "Survey Request[" + request_no + "]", "inbox", "0", "0", "HRLetter", DateTime.Now.ToString(), "1").ToString(); GeneralData.InsertMessageHistory(messageid, "inbox", DateTime.Now.ToString()); Utilities util = new Utilities(); SendNotificationAll(peoplelinkUserId, "Survey Request[" + request_no + "]", "&lt;span style=\"font-family: Arial; font-size:12px\"&gt;Dear PeopleLink, &lt;br /&gt;&lt;br /&gt;Survey Request is completed.&lt;br /&gt;&lt;br /&gt;Click the link below for more details:&lt;a href='http://" + util.GetValueFromConfigFile("ServerIPAll").ToString() + "/ArabiaHRLetterSurveyForm.aspx?requestid=" + request_no + "&amp;surveyid=" + survey_id + "&lt;br /&gt;&lt;br /&gt;Thank you&lt;br/&gt;", "", ""); AlertMessage("Survey Request Completed"); Response.Redirect(Page.ResolveUrl("~/HRLetter\\Arabia\\ArabiaHRLetterSurveyForm.aspx?userid=" + hUserIdEncrypted.Value + "&amp;requestid=" + request_no)); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload