1

I'm trying to default set a radio button with HTML. In the browser I have:

<label><input type="radio" checked="checked" name="optradio" i="1">Nein</label>

But the radio button is not selected.

What do I do wrong?

Screenshot: enter image description here

Michael
  • 6,823
  • 11
  • 54
  • 84

2 Answers2

4

My bad. I had another radio button later on the page that was also checked and had the same name="optradio". It would uncheck the first no matter where it is ~~:-|

$(function() {
  $("div").html( `
    <div class="radio radio1">
    <label><input type="radio" checked="checked" name="optradio" i="1">Nein</label>
    </div>

    <div class="radio radio3">
    <label><input type="radio" checked="checked" name="optradio" i="3">2</label>
    </div>
` )
;  
})

See Codepen: https://codepen.io/lafisrap/pen/yXVyWR?editors=1010

Michael
  • 6,823
  • 11
  • 54
  • 84
-1

enter image description heretry this ,

<label><input type="radio" name="optradio" checked>Nein</label>

we can also use single checked rather then using checked="checked".

if u need further clarifications please read and try this. https://www.w3schools.com/tags/att_input_checked.asp

Archelese
  • 21
  • 9
  • 1
    While the shorthand version is perfectly valid (and explicitly prefered in HTML 4), there are no even remotely modern browsers that have any problem with the long form. This makes no difference. – Quentin Jun 15 '17 at 09:06
  • "if u need further clarifications please read and try this" — No! While W3Schools is a lot better than it used to be, that is damning it with faint praise. It is still very misleading in many places and should be avoided. – Quentin Jun 15 '17 at 09:16
  • 1
    but it can help you in certain points, when you just want to see some examples or just grab some syntax. doesn't matter if whole website is useful for us or not, at this moment, he can see a example and edit it if he is still confused. – Archelese Jun 15 '17 at 09:20
  • A good guide can help as well, without as much misleading and unsecure junk. – Quentin Jun 15 '17 at 10:09