chromedude
chromedude

Reputation: 4302

Is this the correct way to check with javascript if a radio button is checked?

I have the below code but it is not working. Is this correct?

var diffLvl = document.getELementById('lvlDiff');
var interLvl = document.getElementById('lvlInter');
var simpLvl = document.getElementById('lvlSimple');

if (simpLvl.checked) {
    //do stuff
  } else if (interLvl.checked){
    //do stuff
  } else {
    //do stuff
  }

Upvotes: 0

Views: 113

Answers (2)

Guffa
Guffa

Reputation: 700342

Yes, it's correct except for a spelling error.

Javascript is case sensetive. Change getELementById to getElementById.

Upvotes: 5

Julio Santos
Julio Santos

Reputation: 3895

You have [...]getEL[...] on the first line. The L should be lowercase.

Upvotes: 3

Related Questions