Hi Everybody

I have an Access database that passes a Parameter to a web page
something like this.
http://localhost/index.htm?paramName=1234-54321

I want to be able to retrieve the parameter (In this example
1234-54321) and pass it to a text box on a form. Something like this.

<form name="form1" id="form1" method="post" action="">
<input type="text" name="txtinput" value= "Param" />
</form>

Any help gratefully received

Re: Retrieve Parameter from location bar by Marcello

Marcello
Sat May 06 15:12:16 CDT 2006

Try getting window.location.href in your script. Should return your
http://localhost/index.htm?paramName=1234-54321; then you can parse it
to get whatever you need...

There might be an easier way, but I don't recall right now...


Re: Retrieve Parameter from location bar by bobdydd

bobdydd
Sat May 06 16:35:26 CDT 2006

Hi Marcello

I am not too familiar with javascscipt yet but I have found this coding
that almost does what I want but I am not fluent enough with javascript
to achieve the effect I want.........which is to have a text box on the
form which receives the # 1234-54321 from
the http://localhost/index.htm?paramName=1234-54321...Url

Thanks for the prompt reply

Bob

<html>
<head>
<title>Test</title>
<script>
function parseGetVars() {
var getVars = new Array();
var qString = unescape(top.location.search.substring(1));
var pairs = qString.split(/\&/);
for (var i in pairs) {
var nameVal = pairs[i].split(/\=/);
getVars[nameVal[0]] = nameVal[1];
}
return getVars;
}
</script>
</head>

<body>
<script>
var g = parseGetVars();
for (var i in g)
document.writeln(i+'='+g[i]+'<br>');
</script>

</body>
</html>


Re: Retrieve Parameter from location bar by Tim

Tim
Sat May 06 18:42:41 CDT 2006

Try this:

<script>
function GetQSVal(pName) {
var qString = unescape(top.location.search.substring(1));
var pairs = qString.split(/\&/);
for (var i in pairs) {
var nameVal = pairs[i].split(/\=/);
if(nameVal[0]==pName) return nameVal[1];
}
return "";
}

function popText(){
var v = GetQSVal("paramName");
document.getElementById("idTextInput").value = v;
}

</script>

<body onload="popText();">
....


Tim


"bobdydd" <reallyuseful2004@yahoo.co.uk> wrote in message news:1146951326.718945.254640@y43g2000cwc.googlegroups.com...
> Hi Marcello
>
> I am not too familiar with javascscipt yet but I have found this coding
> that almost does what I want but I am not fluent enough with javascript
> to achieve the effect I want.........which is to have a text box on the
> form which receives the # 1234-54321 from
> the http://localhost/index.htm?paramName=1234-54321...Url
>
> Thanks for the prompt reply
>
> Bob
>
> <html>
> <head>
> <title>Test</title>
> <script>
> function parseGetVars() {
> var getVars = new Array();
> var qString = unescape(top.location.search.substring(1));
> var pairs = qString.split(/\&/);
> for (var i in pairs) {
> var nameVal = pairs[i].split(/\=/);
> getVars[nameVal[0]] = nameVal[1];
> }
> return getVars;
> }
> </script>
> </head>
>
> <body>
> <script>
> var g = parseGetVars();
> for (var i in g)
> document.writeln(i+'='+g[i]+'<br>');
> </script>
>
> </body>
> </html>
>



Re: Retrieve Parameter from location bar by Danny

Danny
Sat May 06 19:49:22 CDT 2006




http://localhost/index.htm?paramName=1234-54321

myquerystring=location.href.substring(location.href.indexOf('='))


Danny

Re: Retrieve Parameter from location bar by RobG

RobG
Sun May 07 01:37:55 CDT 2006

bobdydd wrote:
> Hi Marcello
>
> I am not too familiar with javascscipt yet but I have found this coding
> that almost does what I want but I am not fluent enough with javascript
> to achieve the effect I want.........which is to have a text box on the
> form which receives the # 1234-54321 from
> the http://localhost/index.htm?paramName=1234-54321...Url
>
> Thanks for the prompt reply
>
> Bob
>
> <html>
> <head>
> <title>Test</title>
> <script>

The type attribute is required:

<script type="text/javascript">

> function parseGetVars() {

I'd rather call it 'getSearchParams'.

> var getVars = new Array();

This function uses an array like an ordinary object, so it may as well
use one (unless you want to use its array-ness for something else):

var getVars = {};


> var qString = unescape(top.location.search.substring(1));
> var pairs = qString.split(/\&/);
> for (var i in pairs) {
> var nameVal = pairs[i].split(/\=/);
> getVars[nameVal[0]] = nameVal[1];
> }
> return getVars;
> }

To get a particular parameter value, you can do:

var searchParams = getSearchParams();
var paramValue;
if ( (paramValue = searchParams[paramName]) ){
// do something with paramValue
} else {
// paramName was not in the searchstring
// deal with it...
}

[...]

--
Rob