Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 14th, 2007, 10:39 PM
Registered User
 
Join Date: Jun 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Submit Form with QueryString Data

This might seem simple. I know how to do this in ASP.NET but want to try it in JavaScript:

Have an online application that only accepts "POST" form data (hidden in HTML header) I want to submit data to the application using a querystring instead.

So, I want to make an intermediate Javascript page that accepts a querystring URL, take the querystring, put it into the form and then "POST" the form to the application.

I know how to get the querystring:
document.location.search.substring(1,7)

I know how to submit the form:
document.frmFormName.submit()

I just don't know how to put the querystring into the form so it can be submitted

Sorry if this is exceedingly obvious.
Reply With Quote
  #2 (permalink)  
Old June 15th, 2007, 01:49 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

If you know what fields will be represented then it's not too difficult. Create an HTML page with the requisite form and text inputs representing your query string, e.g. if your querystring was forename=joe&surname=fawcett then have two textboxes named forename and surname.
Read the querystring using the search property and create an array using the split method with & as the separator. For each item in the array split agin on the = character and check the value of the first element, this will be forename or surname in the example. Assign the second element of the array to the appropriate textbox. Then call document.forms[0].submit() to submit the form. You can debug all this by having a confirm() in between assigning the values and submitting to see if everything is okay.

A completely different approach would be to use the XMLHttpRequest. Capture the querystring as before. Open a connection to the new URL with the POST method and send the entire querystring as the data argument to the send method. That way, as long as there's a one-to-one mapping between the originally querystring and the new parameters you don't need to parse the querystring at all.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old June 15th, 2007, 10:14 AM
Registered User
 
Join Date: Jun 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is what I need help on:

"Assign the second element of the array to the appropriate textbox"

I need to get the querystring into the value= of the input box in the form. I know how to get the querystring and I know how to submit the form.

Thanks very much for your help. Again, sorry if this is exceedingly obvious.
Reply With Quote
  #4 (permalink)  
Old June 15th, 2007, 10:45 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

document.forms[0].elements["forename"].value = <whatever>

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #5 (permalink)  
Old June 15th, 2007, 06:11 PM
Registered User
 
Join Date: Jun 2007
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Perfect thanks!

I tweaked a little after understanding the concept. Here is the complete code. Again, I had a POST type form page on our intranet that I was not going to be able to get the vendor to change to a querystring page. I wanted an intermediate page in Javascript that would take a querystring URL, put it into a POST form and submit the form:

<html>
<head>
<title>Intermediate Page</title>
</head>
<body>
<form name="frmSearch" method="POST" action="http://intranet.humenahumena.com/Search.jsp">
<input type="hidden" name="txtSearch" value="">
</form>
<script language="javascript">document.frmSearch.txtSearch .value = document.location.search.substring(1,7);
document.frmSearch.submit();
</script>
</body>
</html>
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Refresh Data when Submit Form ruso77 Infopath 0 April 13th, 2007 02:30 PM
submit data to db with html form....(help) PeterJB Beginning PHP 2 August 6th, 2006 12:07 AM
Submit repeated data item in a form using Struts somnathp Javascript How-To 0 July 26th, 2005 12:34 AM
How to send form data without pressing SUBMIT eapsokha Classic ASP Professional 2 March 1st, 2004 09:58 AM



All times are GMT -4. The time now is 10:39 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.