Solved

JQuery accessing attributes from click event

Posted on 2011-09-18
4
282 Views
Last Modified: 2012-05-12
I am working with JQuery 1.4 and Visual Studio 2010.

I have a radio button:

<div>
     <asp:RadioButton runat="server" ID="C" Text=" ..." code="cd" />
</div>

and a click event handler:

$(document).ready(function () {
 var rb = '#<%=myID.ClientID%>';  
 $(rb).click(function () {
        var code = $(this).attr("code");
   });
});

I need to get the button's attributes, but they come in undefined.  How can this be fixed?
Thank you.
0
Comment
Question by:Mare22
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 

Author Comment

by:Mare22
ID: 36557675
well, actually, I am running the code from my previous question:

        $(":radio", ".petsRadioButton").each(function () {
                $("form").append("<input type='radio' name='" + $(this).attr("name") + "' style='display:none' value='0' />");
        })
        $(":radio:visible", ".petsRadioButton").click(function () {
            var breedCode = $(this).attr("breedCode");
            var txt = $(this).attr("Text");
        debugger
            var $bro = $(":radio[name='" + $(this).attr("name") + "']").not(this);
            if ($bro.val() == "0") {
                $bro.val("1");
                $bro.attr("checked", false);
            }
            else {
                $bro.val("0");
                $bro.trigger("click");
            }

            var checked =  $(this).attr("checked");
            if (checked == undefined) {
                checked = false;
            }
            else {
                checked = true;
            }

        });

breedCode and txt are undefined.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36557701
you should be able to use : $(this).next("label").text()

Check this page, the html is the one generated by .net : http://jsfiddle.net/EAvsh/5/
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36557703
            $(':radio:visible').click(function () {
                var $bro = $(":radio[name='" + $(this).attr("name") + "']").not(this);
                if ($bro.val() == "0") {
                    $bro.val("1");
                    $bro.attr("checked", false);
                }
                else {
                    $bro.val("0");
                    $bro.trigger("click");
                }
                var text = $(this).next("label").text();
                alert(text);
            });

Open in new window

0
 

Author Closing Comment

by:Mare22
ID: 36571670
I've actually used $(this).parent, but your comment helped.
Thank you.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question