Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Retrieve Parameter from location bar

Reply
Thread Tools

Retrieve Parameter from location bar

 
 
bobdydd
Guest
Posts: n/a
 
      05-06-2006
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

 
Reply With Quote
 
 
 
 
Marcello
Guest
Posts: n/a
 
      05-06-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...

 
Reply With Quote
 
 
 
 
bobdydd
Guest
Posts: n/a
 
      05-06-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>

 
Reply With Quote
 
Danny
Guest
Posts: n/a
 
      05-07-2006



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

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


Danny
 
Reply With Quote
 
ASM
Guest
Posts: n/a
 
      05-07-2006
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>
</head>
<body>
> <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[i] = myParams[i].split('=');
eval(myParams[i][0]+"='"+myParams[i][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[i].name && f[i].type=='text')
{
var oName='';
if(eval(f[i].name))
{
eval('oName='+f[i].name);
f[i].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>


--
Stephane Moriaux et son [moins] vieux Mac
 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      05-07-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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to get the text from browser location bar *before*navigation (e.g. not location.href) Alex Bird Javascript 3 05-09-2008 02:15 PM
Location, location, location =?Utf-8?B?VHJhY2V5?= Wireless Networking 2 02-17-2007 08:37 PM
Re: disable title bar, status bar, and address bar of a browser window John Hann ASP .Net 0 08-21-2004 05:07 AM
disable title bar, status bar, and address bar of a browser window Matt ASP .Net 0 08-21-2004 03:50 AM
Encrypit the query string value in location bar /Status bar idsplay Jawahar Rajan ASP General 5 07-17-2003 02:02 PM



Advertisments