Reputation: 4565
Is there any reason why I'm not able to see object values from JavaScript using Firefox, but IE and Chrome see them without problem?
For example:
<div>
<input type="text" id="clientID" />
<input type="submit" id="search" value="Submit" class="submitButton" />
</div>
JavaScript:
<script type="text/javascript">
$(document).ready(function () {
$("#searchDisputes").click(function () {
if(clientID.value.toString() != "") {
//do something
}
}
}
</script>
Firefox tells me that clientID
does not exist, however IE and Chrome work just fine.
I am able to access it using jQuery $("#clientID")
, but before changing a good bit of code around, I would like to understand why this doesn't work in Firefox, but works ok in other browsers.
Upvotes: 1
Views: 173
Reputation: 943586
You are assuming that giving an element an id will create a global variable with the same name as the id containing a reference to the element. There is no reason browsers should do this.
Upvotes: 2