Query string parser redirects to new page

Discussion in 'Javascript' started by allan_msdn@hotmail.com, Jan 25, 2006.

  1. Guest

    Hi,

    I'm working on a web-site for a company and part of the site has an
    employee profile page. I need to pass different fields of information
    for each employee to a e-mail a e-mail form. I have tried to pass the
    information appended to a query screen. I have download a Javascript
    query string parser to get the key/value pairs. I don't know
    JavaScript well and avoid using it much, but I'm thinking someone who
    knows it well could solve my problem.

    I start at an employee profile page, hard code the link and append the
    key/value pairs to the link which call a web-form page. I want to
    populate the web-form page with data send from the employee profile
    page. The web-form page contains the Javascript for parsing the query
    string and also contains the html for the web-form. I would like to
    populate certain fields in the web-form page for the visitor who uses
    the webmail forms.I have two questions. First of, I don't know why the
    Javascript code executes when I don't call any of its functions, but
    most importantly why, any other code I include, like simple Alerts to
    check values opens up on a third blank page. This is driving me crazy.

    Here's the query parser:

    function PageQuery(q) {
    if(q.length > 1) this.q = q.substring(1, q.length);
    else this.q = null;
    this.keyValuePairs = new Array();
    if(q) {
    for(var i=0; i < this.q.split("&").length; i++) {
    this.keyValuePairs = this.q.split("&");
    }
    }
    this.getKeyValuePairs = function() { return this.keyValuePairs; }
    this.getValue = function(s) {
    for(var j=0; j < this.keyValuePairs.length; j++) {
    if(this.keyValuePairs[j].split("=")[0] == s)
    return this.keyValuePairs[j].split("=")[1];
    }
    return false;
    }
    this.getParameters = function() {
    var a = new Array(this.getLength());
    for(var j=0; j < this.keyValuePairs.length; j++) {
    a[j] = this.keyValuePairs[j].split("=")[0];
    }
    return a;
    }
    this.getLength = function() { return this.keyValuePairs.length; }
    }

    function queryString(key){
    var page = new PageQuery(window.location.search);
    return unescape(page.getValue(key));
    }

    function displayItem(key){
    if(queryString(key)=='false')
    {
    document.write("you didn't enter a ?name=value querystring item.");
    }
    else
    {
    document.write(queryString(key));
    }


    }

    I'd really appreciate if someone could tell me why any other code I try
    to execute runs on a third page. Ideally, I'd simply like to populate
    the fields on each call to the webform like:

    document.testform.datefield.value = dateString;

    Thanks for any help,
    Al
    , Jan 25, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gery D. Dorazio
    Replies:
    0
    Views:
    446
    Gery D. Dorazio
    Jan 29, 2004
  2. Replies:
    1
    Views:
    310
    Nicole Calinoiu
    Feb 2, 2005
  3. Replies:
    2
    Views:
    5,282
  4. Mark Andrews
    Replies:
    3
    Views:
    114
    Roland Hall
    Jun 8, 2004
  5. nick
    Replies:
    1
    Views:
    440
    David Mark
    Feb 13, 2011
Loading...

Share This Page