怎么在一个框架中通过javascript置值提交另外一个框架中的表单

如何在一个框架中通过javascript置值提交另外一个框架中的表单?
页面test.htm中的代码为:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<frameset rows="90,*" frameborder="no" border="0" framespacing="0">
<frame name="topFrame" src="test1.htm" frameborder="0" border="0" scrolling="auto">
<frame name=""mainFrame" src="http://xxx.com/login" frameborder="0" border="0" scrolling="auto">
</frameset>
</html>


页面test1.htm中的代码为:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language=JavaScript>
window.onload=function(){
top.mainFrame.document.loginform.Username.value='用户名';
top.mainFrame.document.loginform.Password.value='密码';
top.mainFrame.document.loginform.submit();
}
</script>
</head>
<body>
</body>
</html>


想通过在test1.htm中的javascript置值,提交另外一个页面中的表单,但是不起作用,另外一个框架中的页面http://xxx.com/login没有被响应提交,请教大家如何可以实现我说的这种效果?谢谢!

------解决方案--------------------
js
window.onload=function(){
    var iframe = document.getElementById("mainFrame");
iframe.onload = function() {
    var iframeDoc = iframe.contentDocument 
------解决方案--------------------
 iframe.contentWindow.document;
    iframeDoc.loginform.Username.value='用户名';
    iframeDoc.loginform.Password.value='密码';
    iframeDoc.loginform.submit();
}

}

html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<frameset rows="90,*" frameborder="no" border="0" framespacing="0">
<frame name="topFrame" src="test1.htm" frameborder="0" border="0" scrolling="auto">
<frame name="mainFrame" id='mainFrame' src="http://xxx.com/login" frameborder="0" border="0" scrolling="auto">
</frameset>
</html>