Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Strin in HTML

Status
Not open for further replies.

tokool

Programmer
Nov 6, 2001
40
0
0
US
I have opend a .html file to which i have passed a Quey string.
How can i display the values passed in the query string in the html page.
For eg:
i have the following page:

I have a day_of_the_month.htm file where i would like to display the value of lname and fname.
i try the code
Last Name:<%Request.QueryString(&quot;lname&quot;)%><br>
but i see nothing
Apprecite the help
Thanks,
Preetham.
 
Your page needs to be named with the .asp extension.

day_of_the_month.asp instead of .htm
 
can't i extract the query string in a .html page.
 
>>can't i extract the query string in a .html page?<<

You can, but it's MUCH easier with an .asp page. On an .htm page, you'll need to use javascript to get the contents of the querystring using window.location.search(), then you'll need to parse the string, remove the question mark, and retrieve the name=value pairs from an array. I can't remember how to do it off hand. You might want to ask in the javascript forum, or do a search on javascript sites for passing data in a query string.
 
Here's an FAQ from the Javascript section of this site:

faq216-343
 
Like this:

Code:
// This function is replace function

function sReplace (search, replace, string) {
  while (string.indexOf (search) > -1) {
    pos = string.indexOf (search);
    string = (string.substring (0, pos) + replace +
    string.substring ((pos + search.length), string.length));
  }
  return string;
}

// This function reads query string keys and values into arrays

qStr.keys = new Array ();
qStr.values = new Array ();

function qsParse () {
  var query = window.location.search.substring (1);
  var pairs = query.split (&quot;&&quot;);
  for (var i = 0; i < pairs.length; i++) {
    var pos = pairs[i].indexOf ('=');
    if (pos >= 0) {
      var argname = pairs[i].substring (0,pos);
      var value = pairs[i].substring (pos+1);
      qStr.keys[qStr.keys.length] = argname;
      qStr.values[qStr.values.length] = sReplace ('+',' ', unescape (value));
    }
  }
}

qsParse ();

// This function returns the value of a query string key

function qStr (key) {
  var value = &quot;&quot;;
  for (var i = 0; i < qStr.keys.length; i++) {
    if (qStr.keys[i] == key) {
      value = qStr.values[i];
      break;
    }
  }
  return value;
}

Then you just use: qStr (&quot;lname&quot;);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top