473,406 Members | 2,390 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,406 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 2041
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: 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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.