I have a function that is called whenever a select changes. If the select had an ID of "foo" there'd be a text field with an ID of "foo_other" after it that by default is styled "display:none".
If a value of "Other" is picked from the select, the function is supposed to display the text field, and set focus to it. If anything other than "Other" is chosen, it should hide the field and remove anything entered.
Works in FF, IE throws an error "Object required". I was trying to avoid doing an eval() around the dynamic variable... Any help is appreciated.
Code:
function checkOther(inObj){ var other_form_id = inObj.name + "_other"; if(inObj.value == 'Other') { document.getElementById(other_form_id).st开发者_运维知识库yle.display = 'inline'; document.getElementById(other_form_id).focus(); } else { document.getElementById(other_form_id).style.display = 'none'; document.getElementById(other_form_id).value = ''; } }
My guess is you are having multiple IDs in one document (which is invalid), and IE is more picky about it than FF is. Could that be?
The stupid idiots from microsoft are getting the first id OR NAME. I have a dynamically generated javascript and name and id of one html element (input) are different. But instead getting the element with specified ID, the idiots of IE8 are getting the first element with that NAME.
I believed they are idiots even i was working 15+ years as windows (visual studio) developer, but i didn't expect such a stupidness ...
Even later, Hope this will help someone else, not the author of the post.
My solution was to add "id_" prefix for the id tag in order to be sure that the idiots are going to get exactly the normal one, nad not another with with the same name. In my case i'm using id tag for javascript things and the name tag for saving to the DB when the form is sent.
精彩评论