Solved

Javascript - Auto Submit Form

Posted on 2011-03-16
3
492 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
ID: 35152184
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
ID: 35152219
Spot on - thank you, I missed some variables :)
0
 

Author Closing Comment

by:garethtnash
ID: 35152228
Thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article discusses how to create an extensible mechanism for linked drop downs.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

929 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

13 Experts available now in Live!

Get 1:1 Help Now