Solved

Javascript - Auto Submit Form

Posted on 2011-03-16
3
495 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

733 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