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>