Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

extreme n00b question

  • 23-06-2006 11:10am
    #1
    Registered Users, Registered Users 2 Posts: 4,225 ✭✭✭


    I'm emabarrassed to ask this but i'm drawing a complete blank :o
    How do you read the parameters from a http req? e.g from
    http://www.foo.com/home.html?param1=test&param3=123
    

    want to use the parameters in an onload function to make decisions on what to display.


Comments

  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    What language are you using? Or are you trying to do it through Javascript?


  • Registered Users, Registered Users 2 Posts: 4,225 ✭✭✭Scruff


    sorry, yeah using javascript.


  • Registered Users, Registered Users 2 Posts: 3,594 ✭✭✭forbairt


    like gandalf said ... YOU SHALL NOT PARSE ...

    oh wait ... in this case I reckon you need to parse the url ...
    <script type="text/Javascript">
    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[i] = this.q.split("&")[i];
    }
    }
    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')
    {
    alert("you didn't enter a ?name=value querystring item.");
    }else{
    alert(queryString(key));
    }
    }
    </script>
    <body onload="displayItem('name');">
    <form action="test.php" method="get">
    
    <input name="name" type="text" />
    <input type="submit" />
    </form>
    


Advertisement