将变量传递给表单动作脚本

时间:2013-09-21 08:50:14

标签: javascript html

我是javascript的新手,能不能指出我正确的方向来完成以下代码?

我有一个页面可以自动登录我的网站进行工作,但我正在寻找一种方法,可以从ini文件中读取登录凭据,或者只是使用document.write,以便更轻松地传递和在我的HTML中更改这些凭据,其中包含大量这些按钮。

<script language="javascript">


var username = "firstusername";
var password = "firstpassword";


<!-- link -->
<form action="***************" method="post"  target="_blank">
<p>
<input type="hidden" name="HdnCallingProgram" value="login"/>
<input type="hidden" name="HdnAction" value="Login"/>
<input type="hidden" name="txtUserId" value="document.write(username)"/>
<input type="hidden" name="txtPassword" value="document.write(password)"/>
<input type="hidden" name="chkRemember" value="1"/>
<a class="button1" title="Bij fout aanmelden : gebruik browser back button en terug op knop klikken"  onclick="parentNode.parentNode.submit()">Cafe</a>
</p>
</form>


</script>

感谢您阅读本文!

1 个答案:

答案 0 :(得分:1)

<form action="***************" method="post"  target="_blank">
    <p>
        <input type="hidden" name="HdnCallingProgram" value="login"/>
        <input type="hidden" name="HdnAction" value="Login"/>
        <input type="hidden" id="txtUserId" name="txtUserId" value=""/>
        <input type="hidden" id="txtPassword" name="txtPassword" value=""/>
        <input type="hidden" name="chkRemember" value="1"/>
        <a class="button1" title="Bij fout aanmelden : gebruik browser back button en terug op knop klikken"  onclick="this.parentNode.parentNode.submit()">Cafe</a>
    </p>
</form>

<script type="text/javascript">
var username = "firstusername";
var password = "firstpassword";

document.getElementById('txtUserId').value = username;
document.getElementById('txtPassword').value = password;
</script>