Solved

Javascript - Auto Submit Form

Posted on 2011-03-16
3
487 Views
Last Modified: 2012-06-27
I have a senario, where my client operates on many platforms, all that require their users to login and in most cases with different credentials for each platform.

I have suggested a master slave relationship, whereby the master site maintains a database that stores all other platform login details.

So upon logging into the master site, the user can easily login to any of the slave sites, without needing to enter additional login details.

The login details for each slave site would be stored in a database record.

However having looked at some of the existing platforms, they all use the "post" methods for the login form, so I was planning on therefor submittin g the form via javascript...

(I've tried the code below, but it doesn't work) Is this because the target (action) is on another domain / server, or is there something wrong with the javascript?

Many thanks

<body onload="submitForm()">
<form method="post" action="http://www.slavedomain.co.uk/index.php" name="myForm" id="myForm">
<input type="hidden" name="username" value="candidate" />
<input type="hidden" name="passwd" value="candidate" />
</form>
<!-- now send the form! -->
<script type='text/javascript'>document.myForm.submit();</script>
</body>

Open in new window

0
Comment
Question by:garethtnash
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
sjklein42 earned 500 total points
Comment Utility
I tried your code and it worked for me.  I changed the action to point to my web site so i could test it.

I tried it on both IE and Firefox.

Cross-domain link is not an issue.

The onload=...  in the body tag is extraneous and may be causing a quiet error.  You are doing the submit using in-line javascript (document.myForm.submit();)  It might be better to do it in the onload anyway:

Try this:

<body onload="document.myForm.submit();">
<form method="post" action="http://www.slavedomain.co.uk/index.php" name="myForm" id="myForm">
<input type="hidden" name="username" value="candidate" />
<input type="hidden" name="passwd" value="candidate" />
</form>
</body>

Open in new window

0
 

Author Comment

by:garethtnash
Comment Utility
Spot on - thank you, I missed some variables :)
0
 

Author Closing Comment

by:garethtnash
Comment Utility
Thank you
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
lastpass auto fill login form 5 22
Hovering effect 9 28
JavaScript error 1 33
jqplot Pie Chart - javascript 2 7
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now