Retrieve Parameter from location bar

B

bobdydd

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
 
B

bobdydd

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.split(/\=/);
getVars[nameVal[0]] = nameVal[1];
}
return getVars;
}
</script>
</head>

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

</body>
</html>
 
A

ASM

bobdydd a écrit :
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.

<head>
<script type="text/javascript">
if(self.location.search.length > 1)
var myParam = self.location.search.split('=')[1];
onload = function() {
document.forms['form1'].elements['txtinput'].value = myParam;
}
</script>
<form name="form1" id="form1" method="post" action="">
<input type="text" name="txtinput" value= "Param" />
</form>

With several parameters

<script type="text/javascript">

var txtinput, txtinput2;

if(self.location.search && self.location.search.length > 1)
{
var myParams = self.location.search.split('?')[1]+'';
if(myParams.indexOf('&')>=0) {
myParams = myParams.split('&')
for(var i=0;i<myParams.length;i++)
{
myParams = myParams.split('=');
eval(myParams[0]+"='"+myParams[1]+"'");
}
}
else
{
myParams = myParams.split('=');
eval(myParams[0]+" = '"+myParams[1]+"'");
}
window.onload = function() {
var f = document.forms['form1'].elements;
for(var i=0;i<f.length;i++) {
if(f.name && f.type=='text')
{
var oName='';
if(eval(f.name))
{
eval('oName='+f.name);
f.value = oName;
}
}
}
}
}
</script>

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

RobG

bobdydd said:
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:

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.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...
}

[...]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top