0

I have the following code

<input type="radio" name="HotelSearch_Measure" value="Miles">
<input type="radio" name="HotelSearch_Measure" value="KM">

However when I use the following it works in IE9/Chrome/Firefox but not in IE6

jQuery("input[value='Miles'").attr("checked", true);

I've tried searching with no luck.

Thanks in advance.

Rav
  • 703
  • 4
  • 13

4 Answers4

2

I believe this will work for IE6 and for the other browsers also

jQuery("input[value='Miles']").attr("checked", "checked");
mark-cs
  • 4,677
  • 24
  • 32
1

If you are using jQuery < 1.6
do this:

jQuery("input[value='Miles']").attr("checked", 'checked');

If you are using jQuery 1.6+:

jQuery("input[value='Miles']").prop("checked", true);

See this question: .prop() vs .attr() and Possible bug in jQuery 1.6 - $(...).attr("checked") is not working for references why.

Community
  • 1
  • 1
Naftali
  • 144,921
  • 39
  • 244
  • 303
0

Provided your typo (jQuery("input[value='Miles']").attr("checked", true);) occurred when typing your question, and isn't present in your live code, what you have is the correct way to do it, prior to jQuery 1.6.0.

With the new version however, the new method prop() should be used:

jQuery("input[value='Miles']").prop("checked", true);
Matt
  • 74,352
  • 26
  • 153
  • 180
0

jQuery 1.6+ uses prop() like this:

jQuery('input[value="Miles"]').prop("checked", true);
Code Maverick
  • 20,171
  • 12
  • 62
  • 114