Question: I have a function where I am dynamically trying to access a DOM element by passing it's id to a function and then adding an event listener to it,this code works perfectly outside a function but it does not work here.The function looks like this:

```
 var count = 0;
 function disableOnCheck(radioId, textBoxId) {
var a = document.getElementById(radioId);
var atext = document.getElementByID(textBoxId)
alert(a.value);
a.addEventListener('click', function (event) {
    alert(count);
    count++;
    if (count === 2) {
        a.checked = false;
        atext.disabled = false;
        count = 0;
        return;
    }
    alert(a.value);
    atext.disabled = true;
});

```

};

I run this using:

disableOnCheck('a','atest');

Also here is a fiddle that I created <http://jsfiddle.net/vamsiampolu/vKkUP/2/>

Answer: 
JavaScript is case-sensitive. It should be :

```
var atext = document.getElementById(textBoxId);

```

instead of 

```
var atext = document.getElementByID(textBoxId);

```

You would have seen an error (*Uncaught TypeError: Object # has no method 'getElementByID'*) in your console if you try to use it.

**Update:**

You are not getting what you want because you pass in the wrong variable in your `disableOnCheck` function. 

You have `disableOnCheck('a', 'atest');`  

when it should be `disableOnCheck('a', 'atext');`

See [Fiddle](http://jsfiddle.net/vKkUP/7/)
First you are attempting to get the element Id by wrong methond, javascript is a case sensitive language

HERE IS A WORKING CODE: 

```
var count = 0;

function disableOnCheck(radioId, textBoxId) {

    var a = document.getElementById(''+radioId);
    var atext = document.getElementById(''+textBoxId); // you were using getElementByID which is wrong
    alert(a.value);;
    a.addEventListener('click', function (event) {
        alert(count);
        count++;
        if (count === 2) {
            a.checked = false;
            atext.disabled = false;
            count = 0;
            return;
        }
        alert(a.value);
        atext.disabled = true;
    });
};

disableOnCheck('a','atext');  // HERE you were using `atest` which is not a element id it's `atext`

```

The fiddle link is [here.](http://jsfiddle.net/vKkUP/8/)