Jeepers Creepers
Jeepers Creepers

Reputation: 115

Why doesn't this simple script work in IE11

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>  

Upvotes: 0

Views: 302

Answers (2)

Denys S&#233;guret
Denys S&#233;guret

Reputation: 382170

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?

Upvotes: 2

kapantzak
kapantzak

Reputation: 11750

You forgot the '#'

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

Upvotes: 0

Related Questions