1
<ul data-role='listview' data-inset='true' data-divider-theme='b'>
    <li data-role='list-divider'>
        <label>Radio Button</label>
    </li>
    <li data-theme='c'>
        <fieldset data-role='controlgroup'>
            <input id='radio1' type='radio' name='Delete' />
            <label for='radio1'>Radio 1</label>
            <input id='radio2' type='radio' name='Delete' />
            <label for='radio2'>Radio 2</label>
        </fieldset>
    </li>
</ul>
<div data-role='navbar'>
    <ul data-inset='true'>
        <li><a data-role='button' href='#' id='delete' data-icon='check'>Ok</a></li>
        <li><a data-role='button' href='#' id='Cancel' data-icon='delete'>Cancel</a></li>
    </ul>
</div>

$("input[type='radio']").checkboxradio("refresh");
var radTrn = $("#radio1").attr('checked');//here it is coming as undefined
var radRstAl = $("#radio2").attr('checked');//here it is coming as undefined    

i m using jquery mobile simple dialog box RAW HTML mode.The radio button checking was working in jquery 1.6.4 and in 1.7.1 it was not working

stian.net
  • 3,928
  • 4
  • 25
  • 38
Ramasamy Kanna
  • 794
  • 3
  • 11
  • 32
  • What does not work? Because you never actually stated what you're really trying to do here. Are you trying to programatically select the radio button, are you trying to test its current state, or something else? Please also post your relevant HTML code. – Sparky Mar 16 '12 at 04:31
  • now i m given relevant HTML code. – Ramasamy Kanna Mar 16 '12 at 10:16

3 Answers3

4

Try this:

$('#check').prop('checked');

Then checkout http://api.jquery.com/prop/

Joe Landsman
  • 2,177
  • 13
  • 9
  • I assumed this may be the issue, though I think `attr()` should still work for this, even in 1.7.1. I mean, i don't see a reason for it not to (unless I've missed something in the docs). – Purag Mar 14 '12 at 04:56
  • The syntax error aside your code should "work". However, it will return the string "checked" instead of boolean true. Is your logic checking for a string value instead of a boolean? – Joe Landsman Mar 14 '12 at 05:06
  • i m using this $('#check').prop('checked'); if i check the radio button then also it is giving false – Ramasamy Kanna Mar 14 '12 at 12:27
  • 1
    could you perhaps past the code you're using to render your radio button? @Joe's code is correct, but it's possible that the selector we're using is missing the point. – rjz Mar 14 '12 at 14:27
  • +1, Definitely get in the habit of using `prop` in place of `attr`, but the root cause of the original problem is still a mystery. OP, please post more code. – Sparky Mar 16 '12 at 04:27
0
$('#check').attr('checked'); 

problem with quotes..i dont see any other compability issue..

You also try $('#check').is(':checked')

Sparky
  • 98,165
  • 25
  • 199
  • 285
sandeep
  • 2,244
  • 1
  • 23
  • 38
  • https://github.com/jquery/jquery-mobile/commit/c1e230f650a27d26142ba52a42dfa1940e85a46c see this this issue only i was getting now they solved thanks for all your replies – Ramasamy Kanna Apr 10 '12 at 05:25
0

If it isn't a simple formatting issue (you've got an extra quote in there), I'd guess that the checked attribute doesn't have a value assigned. That's still valid HTML, but it may throw a wrench in jQuery's cogs.

Fortunately, there's a fairly easy workaround for your test. Just use the :checked pseudo-class as follows:

var isChecked = $('#check').is(':checked');

This will return a boolean (true if it is checked and false if not), so you can use this as an operator.

Purag
  • 16,941
  • 4
  • 54
  • 75
rjz
  • 16,182
  • 3
  • 36
  • 35