You need to use ClientID
if you have server tag. You are not currently using getElementById but you should to get the DOM element for better browser compatibility. If you have framework 4 and above you can use ClientIDMode and do it without ClientID
Javascript
function getWindowSize() {
document.getElementById('<%= test.ClientID %>').value = $(window).width();
document.getElementById('<%= test2.ClientID %>').value = $(window).height();
}
window.onresize = getWindowSize;
HTML
<input type="text" id="test2" value="Test" runat="server" />
<input type="text" id="test" value="Test" runat="server" />