473,236 Members | 1,292 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,236 software developers and data experts.

parse and display parts of query string

Hello,

I have to admit, I'm not very proficient with javascript, and I'm
hoping someone in this group can help.

What I have is some SHTML pages that I need to be able to dissect and
print parts of the query string. I'm using Apache SSI to display the
shtml pages, but as far as I can tell, SSI doesn't have any way to
split apart a variable like this, so that's why I'm turning to
javascript.

For example, let's save I have the following URL:

page.shtml?foo=1234&bar=5678

Can someone show me some simple javascript that I could insert inside
of page.shtml that would print the value of "foo" and "bar".

Also, I'd like to know how to take these values and potentially insert
them into some form fields.

Thank you for your help!
Scott

Jul 23 '05 #1
5 2037
Jay

"Scott" <sm*****@gmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
Hello,

I have to admit, I'm not very proficient with javascript, and I'm
hoping someone in this group can help.
Does this help?
http://support.internetconnection.ne...y_String.shtml

Jay
What I have is some SHTML pages that I need to be able to dissect and
print parts of the query string. I'm using Apache SSI to display the
shtml pages, but as far as I can tell, SSI doesn't have any way to
split apart a variable like this, so that's why I'm turning to
javascript.

For example, let's save I have the following URL:

page.shtml?foo=1234&bar=5678

Can someone show me some simple javascript that I could insert inside
of page.shtml that would print the value of "foo" and "bar".

Also, I'd like to know how to take these values and potentially insert
them into some form fields.

Thank you for your help!
Scott

Jul 23 '05 #2
Hello Jay,

It almost worked. The page is actually loaded as the result of a CGI
script that uses a "Location:" header to cause a redirect.

Here's how it works:

1) user opens "/cgi-bin/script"

2) /cgi-bin/script responds with:
Location: /page.shtml?foo=1234&bar=1234

3) /page.shtml runs the javascript code, but the problem is the
variable this.location = "/cgi-bin/script" (not
"/page.shtml?foo=1234&bar=1234")

Any ideas?

Thanks,
Scott

Jul 23 '05 #3
Scott wrote:
Hello Jay,

It almost worked. The page is actually loaded as the result of a CGI
script that uses a "Location:" header to cause a redirect.

Here's how it works:

1) user opens "/cgi-bin/script"

2) /cgi-bin/script responds with:
Location: /page.shtml?foo=1234&bar=1234

3) /page.shtml runs the javascript code, but the problem is the
variable this.location = "/cgi-bin/script" (not
"/page.shtml?foo=1234&bar=1234")

Any ideas?

Thanks,
Scott


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">

p {
font: normal 13px "times new roman";
}
input {
width: 100px;
text-align: center;
}
</style>
<script type="text/javascript">

function getQval(name)
{
var m,
re = new RegExp('&?' + name + '=([^&]+)');
var Qstr = window.location.search.substring(1);
return (Qstr && (m = Qstr.match(re))) ?
unescape(m[1]) : '';
}

function qPopulate(f_id)
{
var f, el, elname, elval;
if ((f = document.forms[f_id])
|| document.getElementById
&& (f = document.getElementById(f_id)))
{
for (var i = 1, l = arguments.length; i < l; ++i)
{
elname = arguments[i];
if ((el = f.elements[elname])
&& 'undefined' == typeof el[0]
&& (elval = getQval(elname)))
{
el.value = elval;
}
}
}
}

window.onload = function()
{
qPopulate('f1', 'foo', 'bar', 'baz'); //(form name/id, [field names])
}

</script>
</head>
<body>
<p>
The value of "foo" is
<script type="text/javascript">
document.write('<strong> ' + getQval('foo') + '</strong>.');
</script>
</p><p>
The value of "bar" is
<script type="text/javascript">
document.write('<strong> ' + getQval('bar') + '</strong>.');
</script>
</p>
<form name="f1">
<input type="text" name="foo" value="">___foo
<br>
<input type="text" name="bar" value="">___bar
<br>
<input type="text" name="baz" value="">___baz
</form>
</body>
</html>

Jul 23 '05 #4
Scott wrote:
Hello,

I have to admit, I'm not very proficient with javascript, and I'm
hoping someone in this group can help.

What I have is some SHTML pages that I need to be able to dissect and
print parts of the query string. I'm using Apache SSI to display the
shtml pages, but as far as I can tell, SSI doesn't have any way to
split apart a variable like this, so that's why I'm turning to
javascript.

For example, let's save I have the following URL:

page.shtml?foo=1234&bar=5678

Can someone show me some simple javascript that I could insert inside
of page.shtml that would print the value of "foo" and "bar".
document.write(location.search.substring(1).replac e(/&/g,"<BR>"));

Also, I'd like to know how to take these values and potentially insert
them into some form fields.
v=location.search.substring(1).split("&")
x=v.length
while(x--){
window[v[x].split("=")[0]]=v[x].split("=")[1]
}

Mick
Thank you for your help!
Scott

Jul 23 '05 #5
Scott wrote:
1) user opens "/cgi-bin/script"

2) /cgi-bin/script responds with:
Location: /page.shtml?foo=1234&bar=1234

3) /page.shtml runs the javascript code, but the problem is the
variable this.location = "/cgi-bin/script" (not
"/page.shtml?foo=1234&bar=1234")

Any ideas?
Location header value must be an absolute URI (see
RFC 1945, 10.11 and RFC 2616, 14.30), try that first.
PointedEars
-- Was muß ich ändern, damit es wieder funkt?

Eine größere Antenne holen?
-- Mario Müller in dcs.moz
<b0************@ID-110599.news.dfncis.de>
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Polar | last post by:
I am having troubles finding the parse error in this script. I've been checking for weeks. I am too new to the subject I guess. I am trying to show a readord and them have a form at the bottom...
1
by: fowlertrainer | last post by:
Hi ! Sorry, but zope@zope.org is not send mails to me... So I trying with that list... 1.) I want to use query-string, and post datas in combined dictionary. I have a page that I must...
3
by: Ken Bush | last post by:
How can I write an update query that removes part of a field? Like if I have a field with values such as 8/3/68 (a birthday obviously) and I need to put values in a new column but I need...
19
by: linzhenhua1205 | last post by:
I want to parse a string like C program parse the command line into argc & argv. I hope don't use the array the allocate a fix memory first, and don't use the memory allocate function like malloc....
29
by: gs | last post by:
let say I have to deal with various date format and I am give format string from one of the following dd/mm/yyyy mm/dd/yyyy dd/mmm/yyyy mmm/dd/yyyy dd/mm/yy mm/dd/yy dd/mmm/yy mmm/dd/yy
5
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming. FYI Although I have called...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
5
by: meendar | last post by:
Hi, I just want to parse a character string as below Char * c=abcsyd"loddggg"kjskjdfsdf; I need to stripe out loddgg from c (inside ""). How can i do this in c?
2
by: Mufasa | last post by:
Does anybody have any code that will take a search string and parse it in to the appropriate parts? For instance: +google -news -bush TIA - J.
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.