views:

51

answers:

1

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).style.display = 'inline';
        document.getElementById(other_form_id).focus();
    }
    else
    {
        document.getElementById(other_form_id).style.display = 'none';
        document.getElementById(other_form_id).value = '';   
    }
}
A: 

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?

Pekka
I checked and I have unique ID's... Thanks though, and I'll try to be more conscious of the "accepted" part.
Don
@Don strange. Can you `alert()` an actual ID, and edit that in together with the corresponding HTML?
Pekka
@Pekka - thanks for the help. It turns out it was not IE, it was "ME"... I had renameded the first id, so when it tried to append "_other" onto the end of it, it was a different name. Just forgot to rename the text item to match. Thanks for confirming it SHOULD work so I knew to dig deeper.
Don