Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Attempting to submit a form via JavaScript

Posted on 2014-03-21
7
Medium Priority
?
519 Views
Last Modified: 2014-03-21
Hello,

I am attempting to send a form by using the syntax document.getElementById("ID").submit();

Here is my code:

<?php
echo "<form action='../login.php?pass=yes' id='passForm'>
		<input type='hidden' id='usr' value='". $_POST["usr"]. "' />
		<input type='submit' />
	</form>";
?>
<script language="javascript" type="text/javascript">
                document.getElementById("passForm").submit();
</script>

Open in new window


The $_POST["usr"] is from the form that went to this page.  The submit() is only submitting login.php?.  In other words, even the action string is '../login.php?pass=yes, submit is only using '../login.php?.

if I do alert(document.getElementById("passForm").action), the complete string is displayed.

Any help is greatly appreciated.

Have a great day,

Don
0
Comment
Question by:GEMCC
  • 4
  • 3
7 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39946680
Code works fine but pass=yes will not be passed, it will be replaced with any inputs in the form
0
 

Author Comment

by:GEMCC
ID: 39946717
So how do I get the complete URL to submit?
0
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 39946720
Change the FORM METHOD to POST

echo "<form action='../login.php?pass=yes' method='POST' id='passForm'>

Then you can get the url params with $_GET and the FORM values with $_POST
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

by:GEMCC
ID: 39946726
Thanks!  Now it works!  I forgot about method="post"!
0
 

Author Comment

by:GEMCC
ID: 39946739
I kinda jumped too soon to mark the answer as accepted.  I am now getting to the proper URL, but <input type='hidden' id='usr' value='". $_POST["usr"]. "' /> is not being posted.  In other words, the value does not go to ../login.php?pass=yes.

Now what am I doing wrong/ missing?

Thanks for your help!
0
 
LVL 58

Expert Comment

by:Gary
ID: 39946746
Your input needs a name otherwise it won't be POSTed
0
 

Author Comment

by:GEMCC
ID: 39946749
Again, a brain fart, I was thinking about CSS (id).

Thanks again
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Find out what you should include to make the best professional email signature for your organization.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…
Suggested Courses

916 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