1. I suggest you try separating it like this
var txtBox = document.getElementById('<%= txtUserName.ClientID %>');
txtBox.value = "Any value";
I found this to work sometimes I am not sure why and not sure whether it will in your case but you can try.
Also, I think you should start using jQuery because it has use the implementation according to the users browser so we have to worry less about browser dependency COMPARATIVELY if we sue jQuery.
like in jQuery the methos like
will work on all browsers.