473,396 Members | 2,140 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Javascript to add querystring url to hidden form fields

37
Hi,

Is there a way to add the infomation in a url querystring/link to hidden form fields
and submit that form when the user clicks on the link?

Basically I have some paging links generated from a search page which hold a lot of search data and other variables. I need to send this data using the post method as its too much to be sent via the get method employed using a query string.

Any other technique to acheive the above would be appreciated as well. I've considered holding the data in session variables but if these could time out before the user has browsed through all their search results!
Apr 11 '07 #1
6 11433
acoder
16,027 Expert Mod 8TB
You should probably do this on the server-side, but you can use the search property. Parse it and set the hidden form values to the search values.
Apr 12 '07 #2
ozzii
37
You should probably do this on the server-side, but you can use the search property. Parse it and set the hidden form values to the search values.
I dont understand what you mean by doing it on the server side? the paging links/numbers are generated dynamicaly and hold search data in the querystring. When the user clicks on the navigation link the data in that link is so long that the querystring get method will simply truncate. It therefore needs to be sent via the post method. The only way i can think of doin this is through javascript. the paging link would have a onclick even which sends it to a function that adds the search variables to a hidden form and then submits it.

How can you do that on the server side?
Apr 12 '07 #3
ozzii
37
You should probably do this on the server-side, but you can use the search property. Parse it and set the hidden form values to the search values.

Ok I've come up with an idea. I could read all the variables in to one variable and then parse that at the other end. I have the following as example:

Expand|Select|Wrap|Line Numbers
  1. original query string:
  2.  
  3. "mysearchresults.asp?foo=blah&faa=blah&fee=blah&numperpage=10&pagenum=2"
  4.  
  5. myquery = "mysearchresults.asp?foo=blah&faa=blah&fee=blah&numperpage=10&pagenum=2"
  6.  
  7. new url string:
  8. "mysearchresults.asp?query=myquery"
How do i parse the variable myquery into name value pairs in ASP?
Apr 12 '07 #4
acoder
16,027 Expert Mod 8TB
By doing it one the server-side, I meant dynamically generating from the server-side. If, however, you are using javascript, see the link I gave earlier. Parse the search string using string methods, e.g. split() which will split the string into an array (probably using "&" as a delimiter). Then get the form values and set them to the name-value pairs that you derive from the string.
Apr 13 '07 #5
ozzii
37
By doing it one the server-side, I meant dynamically generating from the server-side. If, however, you are using javascript, see the link I gave earlier. Parse the search string using string methods, e.g. split() which will split the string into an array (probably using "&" as a delimiter). Then get the form values and set them to the name-value pairs that you derive from the string.
Ok i've found a script to parse the query string from a url however I get nothing in the parsed variable even thoug I know there is a value for that variable in the query string! Below is the code am using. any suggetions. Do I need to unescape the pair for it to work?

The url link is : "mysearchresults.asp?fpage=1" generated dynamically

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function getQueryVariable(variable) {
  3.   var query = window.location.search.substring(1);
  4.   var vars = query.split("&");
  5.   for (var i=0;i<vars.length;i++) {
  6.     var pair = vars[i].split("=");
  7.     if (pair[0] == variable) {
  8.       return pair[1];
  9.     }
  10.   } 
  11.   alert('Query Variable ' + variable + ' not found');
  12. }
  13. </script>
Apr 17 '07 #6
acoder
16,027 Expert Mod 8TB
Try this script.
Apr 18 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Gowhera Hussain | last post by:
Use This for Learning Only .... Do Not Try To Act Smart HACKING WITH JAVASCRIPT Dr_aMado Sun, 11 Apr 2004 16:40:13 UTC This tutorial is an overview of how javascript can be used to bypass...
3
by: Andy | last post by:
Hi, I am complete JavaScript novice and would really appreciate some help with this code: ===================================================================== <%@LANGUAGE="VBSCRIPT"...
5
by: milkyway | last post by:
Hello everyone, I have a few values and variables that I want to post to a server (without using a SUBMIT button). Is there a way to post data from within javascript - do sockets or connections...
3
by: news.rcn.com | last post by:
How can I access the request and response object for a page using javascript. I want to stick some data on with something like request.setAttribute( "User's choice for later use" ). I can't seem...
5
by: VB Programmer | last post by:
I have a javascript calculator. How do I pass the value of the calculator result to another ASPX page so that I can right some VB.NET against the value? Thanks!
7
by: Andy | last post by:
Hi, I have a complicated question that I'm hoping someone can help me out with. I have a webpage that contains a plug-in. This plug-in can communicate/pass data with the webpage that contains it...
7
by: =?Utf-8?B?QVRT?= | last post by:
HOWTO Make CStr for JavaScript on ASP w/ Request.Form and QueryString In ASP, Request.Form and Request.QueryString return objects that do not support "toString", or any JavaScript string...
5
by: quirk | last post by:
I am trying to write a script where a page is populated with some maths questions, user answers them (it's timed but I've left this bit out), gets results on same page and ajax takes their score,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.