SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    Member ngaisteve1's Avatar
    Join Date
    May 2003
    Location
    Kuala Lumpur, Malaysia (Boleh!)
    Posts
    264
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Grab value from URL

    I have a link like this ... test_popup.asp?s_Postcode=1

    My question is how do I grab this s_Postcode variable. The grabing page look like this at this time.

    Using alert, I can see the whole URL but how do I put that s_Postcode into my textbox?

    <html>
    <script language="JavaScript">
    function get_parameter() {
    var strReturn = "";
    var strHref = window.location.href;
    if ( strHref.indexOf("&") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("&")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
    if (
    aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
    var aParam = aQueryString[iParam].split("=");
    strReturn = aParam[1];
    break;
    }
    }
    }
    return strReturn;
    }
    </script>
    <body onload="get_parameter()">
    <form name=FrmEditContact>
    <table>
    <tr>
    <th>Postcode</th>
    <td><input maxlength="12" size="12" name="s_Postcode" value=""></td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    My Personal HomePage - www.findingsteve.net

  2. #2
    SitePoint Addict Mirek Komárek's Avatar
    Join Date
    Dec 2006
    Location
    Prague
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not sure if I understnd you well. I uploaded one example for you here http://xy.wz.cz/a.html There is an input with undefined value, when you press a link on right side, it will send a value from url to that input.

  3. #3
    SitePoint Enthusiast manish_er's Avatar
    Join Date
    Oct 2005
    Location
    Delhi : India
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    try following code
    Hope it will work


    <html>
    <head>
    <script>
    var loc=window.location.href;
    function doLoad(){
    var qs;
    var paramArray=new Array();
    if(loc.indexOf("?")>=0){
    var urArray=loc.split("?");
    qs=urArray[1];
    if(qs.indexOf("&")){
    var paramStringArray=qs.split("&");
    for(i=0;i<paramStringArray.length;i++){
    var temp=paramStringArray[i].split("=");
    alert(temp[0]+" "+temp[1]);
    paramArray[temp[0]]=temp[1];
    }
    }
    }
    document.getElementById("txt").value=paramArray.param;


    }
    </script>
    </head>
    <body onload="doLoad();">
    <input type="text" id="txt" value="">
    </body>
    </html>

  4. #4
    Member ngaisteve1's Avatar
    Join Date
    May 2003
    Location
    Kuala Lumpur, Malaysia (Boleh!)
    Posts
    264
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    manish_er,

    Thanks. I manage to see the variable name and the value in alert but when I uncomment it, my text show "undefined". How do I go about it now?

    Mirek Komárek,

    I haven't check it out yet. But, will do so now. Thanks.
    My Personal HomePage - www.findingsteve.net

  5. #5
    Member ngaisteve1's Avatar
    Join Date
    May 2003
    Location
    Kuala Lumpur, Malaysia (Boleh!)
    Posts
    264
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mirek Kom&#225;rek,

    I have checked it out. Yes, that is what I want. But I think I just use manish_er's code first. Seem easier for me. Thanks for the help.

    Manish_er,
    I tried to add

    document.getElementById("txt").value = temp[1];
    after

    paramArray[temp[0]]=temp[1];

    and then uncomment out last line

    document.getElementById("s_Postcode").value = paramArray.param;

    then I can see the value in my textbox
    My Personal HomePage - www.findingsteve.net


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •