views:

71

answers:

3

I've created a form that posts to a cfm file. When running a script onLoad that fills in the form values and tries to submit...The site takes me back to the login screen.

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

Please help!


update:

Here is the code....When the values for email and password are filled ini manually and the enter button is pressed it will direct me to the home page. However, when writing a script that submits the form onload, it redirects me to the login page.

<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"&gt; 

    <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> 
+3  A: 

It's hard to tell without the HTML of the form itself, but my guess would be that the action="" attribute of your form is blank. If that attribute is blank, the browser will post the form back to the same page.

Since you're using coldfusion, check to see if there is code generating your action="" value, and look for bugs in it if so. It may help to view the rendered HTML source of the page.

Paul
Ya, debug the form action without JS's submit first...
Henry
A: 

Make sure you aren't using a <cflocation> (or some other redirect) on your destination cfm page that could be redirecting the user back to the form page.

(It would help if you would post your full code)

ibjhb
A: 

Make sure to set the action. Here's the code:

<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>

And of course add the onload attribute to your body tag:

<body onload="f();">

There's a couple of other things to fix in your code. Check it with Total Validator. It's a great tool that will make you a better coder.

Gert G