0

I have a issue with an application and I have recreated the same issue by skinning down the code to the source of the problem. IE11 is returning an error in the console "'test1_1' is undefined"

This code works in Firefox so I need to understand why its not working in IE11. Hoping its something straight forward any help would be appreciated.

jQuery:

function testAlert(row,defect){
    alert(defect);
};

HTML:

 <form>
    <div class="input-group">
       <input type="text" id="test1_1" name="test1_1" style="width:150px" readonly="true" value="test">
          <span class="btn btn-default btn-sm input-group-addon" 
                id="customer_search" 
                onclick="testAlert('1',$(test1_1).val());
          ">
             test
           </span>
    </div>
</form>  
Mardzis
  • 760
  • 1
  • 8
  • 21

2 Answers2

2

Not all browsers set a global variable for elements having an id. And they don't always do it the same way. Using window.yourNodeId to get an element by its id is thus considered unreliable and a bad practice, you should use a selector here instead :

onclick="testAlert('1',$('#test1_1').val());"

Related : Do DOM tree elements with ids become global variables?

Community
  • 1
  • 1
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
0

You forgot the '#'

onclick="testAlert('1',$('#test1_1').val());
kapantzak
  • 11,610
  • 4
  • 39
  • 61
  • 1
    Actually, some browsers store element IDs as global variables. `window.test1_1` will return the element with that ID. IE11 doesn't support this, however. – James Donnelly Jan 07 '15 at 09:47