• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

determine which radio button is selected from group.

I'm trying to determine which radiobutton in a group is selected. I preselect one of the choices. In my debug mode the only thing ever passed is the one preselected. It doesn't send the current one selected.What am I doing wrong?

 <script type="text/javascript">
        $(document).ready(function () {
            $("#<%=txtSearch.ClientID%>").autocomplete("Search.ashx?type=" + $("input:radio[name='toggle']:checked").val(), {
             width: 200,
             formatItem: function(data, i, n, value) {
                 return "<img style = 'width:50px;height:50px' src='Images/doctypes/" + value.split(",")[1] + ".png'/> " + value.split(",")[0];
             },
             formatResult: function (data, value) {
                 $("#<%=hfCustomerId.ClientID %>").val(value.split(",")[2]);
                 return value.split(",")[0];

             }
           
         });
     });
   </script>

Open in new window

0
NickMalloy
Asked:
NickMalloy
  • 3
  • 3
1 Solution
 
Alex_WCommented:
You could get the currently selected radio buttons id:

var id = $("input[@name=RadioButtonGroup]:checked").attr('id');

or get the value's if they are unique:

var value = $("input[@name=RadioButtonGroup]:checked").val();
0
 
leakim971PluritechnicianCommented:
Try this :
	$(document).ready(function () {
		$.ajaxSetup({ data: { "type":$("input:radio[name='toggle']:checked").val() } }); // ADD this param to every jQuery ajax call
		$("#<%=txtSearch.ClientID%>").autocomplete("Search.ashx", {
			width: 200,
			formatItem: function(data, i, n, value) {
				return "<img style = 'width:50px;height:50px' src='Images/doctypes/" + value.split(",")[1] + ".png'/> " + value.split(",")[0];
			},
			formatResult: function (data, value) {
				$("#<%=hfCustomerId.ClientID %>").val(value.split(",")[2]);
				return value.split(",")[0];
			}
		});
	});

Open in new window

0
 
NickMalloyAuthor Commented:
I tried the code above and it still is sending the same radiobutton name everytime. I call the button using this code.

 public void ProcessRequest (HttpContext context)
    {
        string searchText = context.Request.QueryString["q"];
        string Filters = context.Request.QueryString["type"];
       
    }

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
NickMalloyAuthor Commented:
when I debug the jquery it never hits this code again. Only on first load.

 $.ajaxSetup({ data: { "type": $("input:radio[name='toggle']:checked").val() } });

How can I change that?
0
 
leakim971PluritechnicianCommented:
I tried the code above and it still is sending the same radiobutton name everytime. I call the button using this code.
Did you notice I remove the param line 3?

when I debug the jquery it never hits this code again. Only on first load.

 $.ajaxSetup({ data: { "type": $("input:radio[name='toggle']:checked").val() } });

How can I change that?
Don't change it, read the comment line 2

Any live link to see your implementation?
0
 
NickMalloyAuthor Commented:
Complete code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="testsearch.aspx.cs" Inherits="testsearch" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="css/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
    <script src="Jquery1/jquery-1.5.1.min.js"></script>
    <script src="scripts/jquery.autocomplete.js" type="text/javascript"></script>
     <script type="text/javascript">
         $(document).ready(function () {
             $.ajaxSetup({ data: { "type": $("input:radio[name='toggle']:checked").val() } });
             $("#<%=txtSearch.ClientID%>").autocomplete("Search.ashx", {
                 width: 200,
                 formatItem: function (data, i, n, value) {
                     return "<img style = 'width:50px;height:50px' src='Images/doctypes/" + value.split(",")[1] + ".png'/> " + value.split(",")[0];
                 },
                 formatResult: function (data, value) {
                     $("#<%=hfCustomerId.ClientID %>").val(value.split(",")[2]);
		        return value.split(",")[0];
		    }
             });
         });
   </script>
</head>
<body>
    <form id="form1" runat="server">
    Search<br /> <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox><asp:HiddenField ID="hfCustomerId" runat="server" /><br /><br />Filters<br />
    <label class="lightgrey"><asp:RadioButton ID="rdbAll" GroupName="toggle" runat="server"  /><span>All</span></label><br />
    <label class="lightgrey"><asp:RadioButton ID="rdbTest1" GroupName="toggle" runat="server" /><span>Test 1</span></label><br />
    <label class="lightgrey"><asp:RadioButton ID="rdbTest2" GroupName="toggle" runat="server" /><span>Test 2</span></label><br />
    <label class="lightgrey"><asp:RadioButton ID="rdbTest3" GroupName="toggle" runat="server" /><span>Test 3</span></label><br />
    </form>
</body>
</html>

Open in new window


Search file.

<%@ WebHandler Language="C#" Class="Search" %>
using System;
using System.Data.SqlClient;
using System.Text;
using System.Web;
using System.Web.UI;

public class Search : IHttpHandler {
    
    public void ProcessRequest (HttpContext context)
    {
        string searchText = context.Request.QueryString["q"];
        string Filters = context.Request.QueryString["type"];
 
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

Open in new window

0
 
leakim971PluritechnicianCommented:
Thank you, it will work with :
     <script type="text/javascript">
         $(document).ready(function () {
             $("#<%=txtSearch.ClientID%>").autocomplete("Search.ashx", {
                 extraParams: { "type": function () { return $("input:radio[name='toggle']:checked").val(); } },
                 width: 200,
                 formatItem: function (data, i, n, value) {
                     return "<img style = 'width:50px;height:50px' src='Images/doctypes/" + value.split(",")[1] + ".png'/> " + value.split(",")[0];
                 },
                 formatResult: function (data, value) {
                     $("#<%=hfCustomerId.ClientID %>").val(value.split(",")[2]);
                     return value.split(",")[0];
                 }
             });
         });
   </script>

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now