2010-05-10 69 views
1

我创建了张贴到cfm文件的表单。在运行脚本onLoad时,填写表单值并尝试提交...该网站将我带回登录屏幕。自动提交到cfm

<script> 
function f() 
{ 
document.getElementById("email").value = "[email protected]"; 
document.getElementById("password").value = "asdf"; 
document.getElementById("form1").submit(); 
} 
</script> 

请帮忙!


更新:

下面是代码....当电子邮件和密码值手工填写ini和回车键被按下它会告诉我到主页。但是,在编写提交表单的脚本时,它会将我重定向到登录页面。

<form action="https://www.asdf.com/dev/mem/login/login.cfm" method="post" id="caring" name="login" style="margin: 0px; padding: 0px;"> 
<input name="page" type="hidden" id="page" value="https://www.asdf.com/dev/mem/home/home.cfm"> 

    <table> 
    <tr> 

    <td rowspan="2" class="title"></td> 
    <td class="label"><label for="email"></label></td> 
    <td class="element"><input name="email" id="email" value ="[email protected]" /></td> 
    <script> 
    //<td rowspan="2" class="action"><input type="submit" name="login" value="submit" alt="go" title="go" /></td> 
    </script> 
    </tr> 

    <tr> 
    <td class="label"><label for="username"></label></td> 
    <td class="element"><input name="password" value = "asdf" id="password" /></td> 
    </tr> 
<td rowspan="2" class="action"><input type="submit" name="login" value="enter" alt="go" title="go" /></td> 
    <tr> 
    <td></td> 
    <td colspan="2">&nbsp;</td> 
    <td>&nbsp;</td> 
    </tr> 
    </table> 

</form> 
+0

user337786,我编辑了问题以添加您添加为答案的信息 - 请使用问题编辑链接添加任何未来更新。 – 2010-05-13 09:53:52

回答

4

很难说没有窗体本身的HTML,但我的猜测是,表单的action=""属性是空白。如果该属性为空,浏览器会将表单发回到同一页面。

由于您使用的是Coldfusion,请检查是否存在生成action=""值的代码,如果有,请查找错误。这可能有助于查看页面的呈现HTML源代码。

+3

雅,调试没有JS的第一个提交的表单动作... – Henry 2010-05-11 01:09:55

0

确保您的目标cfm页面上没有使用<cflocation>(或其他重定向),可能会将用户重定向到表单页面。

(这将有助于您发布您的完整代码)

0

确保设置操作。下面的代码:

<script type="text/javascript"> 
    function f() { 
    document.getElementById("email").value="[email protected]"; 
    document.getElementById("password").value="asdf"; 
    document.getElementById('caring').action=document.getElementById("page").value; 
    document.getElementById('caring').submit(); 
    } 
</script> 

,当然还有onload属性添加到您的身体标记:

<body onload="f();"> 

还有几个其他的事情在你的代码来解决。用Total Validator检查。这是一个很棒的工具,可以让你成为更好的编码器。