I have the following JavaScript working in IE, but not on Chrome and Firefox.
Here is the code:
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#applicationSelect').change(function() {
document.getElementById('dropdown').value = "APPLICATION";
});
});
</script>
<input type="hidden" name="dropdown" value="" />
When I look in Firebug, the code errs:
document.getElementById("dropdown") is null
document.getElementById('dropdown').value = "APPLICATION";
I need your advice. Thank you in advance.
The problem is that your
inputelement doesn’t have anid! Changenametoid, or add anidtoo:Alternatively, if you don’t want to add an
id, you could usegetElementsByName(which doesn’t work very well cross-browser), or you could use a jQuery attribute selector:Update
I just noticed that you said in your question that it was working in IE. That means you must be using a pretty old version of IE, because
getElementByIdin IE7 and below incorrectly selects elements byname, as well asid.