2

I am getting an error in IE11 when attempting to call a function that is executing on click in a radio button.

Here is the html for the radio button:

<input type="radio" name="filter" value="status" onclick="status()" checked>    

The function is defined at the bottom of the page:

function status(){

    try{
        var td = document.getElementById("check1td");
        td.innerHTML = "Current (CURR)<input type=\"checkbox\" name=\"skustat1\" value=\"CURR\" checked>";

        td = document.getElementById("check2td");
        td.innerHTML = "Test (TEST)<input type=\"checkbox\" name=\"skustat2\" value=\"TEST\" checked>";

        td = document.getElementById("check3td");
        td.innerHTML = "Stocking Internet (SINET)<input type=\"checkbox\" name=\"skustat3\" value=\"SINET\" checked>";

        td = document.getElementById("check4td");
        td.innerHTML = "Sellable Display (SLDSP)<input type=\"checkbox\" name=\"skustat4\" value=\"SLDSP\" checked>";

    }
    catch(err){
        alert(err.message);     
    }
}

I have a similarly defined function on the sibling radio button and it is called correctly. So, my question is, is status() a reserved javascript function that IE won't respond to? And, if so, why does this work in other browsers?

EDIT: changed Status() to status() to reflect how it actually appears in my code.

UPDATE1: It also seems that it works when the browser is first opened in IE, maybe a caching issue?

faircloud
  • 687
  • 6
  • 14

4 Answers4

0

You cant use status as a variable in chrome (possibly other browsers too).

var internal = [];
for(var b in window) { 
  if(window.hasOwnProperty(b)) internal.push(b); 
}
console.log(internal); 

[... "status", ...]

Try renaming it to Status() or anything else. This code works: http://jsfiddle.net/hLmbk6bz/1

Javier Buzzi
  • 6,296
  • 36
  • 50
0

Add an event listener like this:

document.getElementById("clickMe").addEventListener("click", status);

See fiddle: http://jsfiddle.net/bun4g2d0/4/

HTML

<input id="clickMe" type="radio" name="filter" value="status" onclick="status()" checked> 
    <div id="check1td"></div>
    <div id="check2td"></div>
    <div id="check3td"></div>
    <div id="check4td"></div>

javascript

document.getElementById("clickMe").addEventListener("click", status);
        function status(){
    try{
        var td = document.getElementById("check1td");
        td.innerHTML = "Current (CURR)<input type=\"checkbox\" name=\"skustat1\" value=\"CURR\" checked>";

        td = document.getElementById("check2td");
        td.innerHTML = "Test (TEST)<input type=\"checkbox\" name=\"skustat2\" value=\"TEST\" checked>";

        td = document.getElementById("check3td");
        td.innerHTML = "Stocking Internet (SINET)<input type=\"checkbox\" name=\"skustat3\" value=\"SINET\" checked>";

        td = document.getElementById("check4td");
        td.innerHTML = "Sellable Display (SLDSP)<input type=\"checkbox\" name=\"skustat4\" value=\"SLDSP\" checked>";

    }
    catch(err){
        alert(err.message);     
    }
}
Adam Buchanan Smith
  • 9,422
  • 5
  • 19
  • 39
0

It's definitely the "status" name. That's the only difference between this:

http://jsfiddle.net/CrossEye/ux636prr

and this:

http://jsfiddle.net/CrossEye/ux636prr/1/

But the second one, which changes "status" to "Status" works fine.

And an obligatory code link, although that Fiddle uses the same code as the question :smile: :

<input type="radio" name="filter" value="status" onclick="status()" checked>    
Scott Sauyet
  • 49,207
  • 4
  • 49
  • 103
  • Ahh, yes, @epascarello's comments above explain it. It's been a long time since I mucked about with `window.status`.... – Scott Sauyet Oct 19 '15 at 17:39
0

My answer doesn't directly apply to this case, but I had the exact same error caused by a really similar and related problem. My function name was not a reserved word, but was the exact same name as my "name" attribute of my input radio.

<script>
function LoginType()
{
  // Code here never called because the function name is the same as my input name...
}
</script>
<input type="radio" name"LoginType" value="Windows" onclick="LoginType();" />

So I had to change my name like:

<input type="radio" name"radio_LoginType" value="Windows" onclick="LoginType();" />
Matt Roy
  • 1,455
  • 1
  • 17
  • 27