Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Displaying the Query String in the TextField

    Hello Friends...
    I am working on parsing the querystring using javascript
    So I have successfully parsed the querystring & also replace the special character+
    but I want to display the querystring in the TextField Control
    So how to implement it
    Please guide me....

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,103
    Thanks
    80
    Thanked 4,554 Times in 4,518 Posts
    What is a "TextField" control???

    There is no such thing in HTML. Do you mean a <textarea>??
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Quote Originally Posted by Old Pedant View Post
    What is a "TextField" control???

    There is no such thing in HTML. Do you mean a <textarea>??
    Yes I know it.....
    i want to display it in a textarea so how to do this please tell me?
    Thank you....

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,103
    Thanks
    80
    Thanked 4,554 Times in 4,518 Posts
    Then you could just do
    Code:
    document.forms[0].nameOfTextArea.value = theParsedQueryStringInfo;
    You would need to put a newline character ("\n") between each line of information.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New Coder
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Quote Originally Posted by Old Pedant View Post
    Then you could just do
    Code:
    document.forms[0].nameOfTextArea.value = theParsedQueryStringInfo;
    You would need to put a newline character ("\n") between each line of information.
    hello this is my code which display the query string openly but i want it in the TextArea txtMessage
    So please tell me

    <html>
    <head>
    <!-- head stuff -->
    <script type="text/javascript">
    <!-- hide from old browsers

    function getValue(varname)
    {
    // First, we load the URL into a variable
    var url = window.location.href;

    // Next, split the url by the ?
    var qparts = url.split("?");

    // Check that there is a querystring, return "" if not
    if (qparts.length == 0)
    {
    return "";
    }

    // Then find the querystring, everything after the ?
    var query = qparts[1];


    // Split the query string into variables (separates by &s)
    var vars = query.split("&");


    // Initialize the value with "" as default
    var value = "";

    // Iterate through vars, checking each one for varname
    for (i=0;i<vars.length;i++)
    {
    // Split the variable by =, which splits name and value
    var parts =vars[i].split("=");

    // Check if the correct variable
    if (parts[0] == varname)
    {
    // Load value into variable
    value = parts[1];

    // End the loop
    break;
    }
    }

    // Convert escape code
    value = unescape(value);

    // Convert "+"s to " "s
    value.replace(/\+/g," ");

    // Return the value
    return value;
    }


    // end hide -->
    </script>
    </head>
    <body>
    <h1>Sender
    <script type="text/javascript">
    <!-- hide
    var name = getValue("textSender");
    document.write(name+"<br/>");
    // end hide -->
    </script>
    </h1>
    <h2>Received Message
    <script type="text/javascript">
    <!--hide
    var msg=getValue("textMessage");

    for(var i=0;i<msg.length;i++)
    {
    var str=""
    str=msg.charAt(i);
    var ind=msg.indexOf(msg.charAt(i));
    if (msg.charAt(i)=="+")
    {
    msg= msg.replace(msg.charAt(i)," ");
    }
    }
    document.write(msg);
    //end hide-->
    </script>
    </h2>
    <table border=1>
    <tr>
    <td>Receiver</td>
    <td><input type="text" name="txtReceiver" size="10" value="221"></td>
    </tr>
    <tr>
    <td valign="top">Message:<br>(max. 160 chars)</td>
    <td>
    <textarea rows=3 name="txtMessage" cols=38 value=""></textarea>
    </td>
    </tr>
    <tr>
    <td colspan=2><input type="Submit" value="Send"></td>
    </tr>
    </table>
    </body>
    </html>

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,103
    Thanks
    80
    Thanked 4,554 Times in 4,518 Posts
    Man, did you WAY overcomplicate that!

    I *THINK* this is all you need:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    // parse the query string for later ease of use:
    
    var queryString = [ ]; // establish the array we will use
    
    var qs = location.search;
    if ( qs.length > 3 ) 
    {
        var pairs = qs.substring(1).split("&");
        for ( var p = 0; p < pairs.length; ++p )
        {
            var pair = pairs[p].split("=");
            queryString[ pair[0].toLowerCase() ] = 
                decodeURIComponent( pair[1].replace(/\+/g," ") );
        }
    }
    
    function setValues()
    {
        document.getElementById("sender").innerHTML = 
            "Sender " + queryString["textsender"] + "<br/>";
    
        document.forms[0].txtMessage.value = 
            queryString["textmessage"];
    }
    </script>
    </head>
    <body onload="setValues()">
    <form>
    <h1 id="sender"></h1>
    <h2>Received Message
    </h2>
    <table border=1>
    <tr>
    <td>Receiver</td>
    <td><input type="text" name="txtReceiver" size="10" value="221"></td>
    </tr>
    <tr>
    <td valign="top">Message:<br>(max. 160 chars)</td>
    <td>
    <textarea rows=3 name="txtMessage" cols=38 value=""></textarea>
    </td>
    </tr>
    <tr>
    <td colspan=2><input type="Submit" value="Send"></td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    I saved that a the file "queryTest.html" and then I invoked it with the url:
    Code:
    queryTest.html?textSender=joe+dimaggio&textMessage=Now+is the+time%3f%0AGive+up%3f
    And it seemed to me that it worked.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,103
    Thanks
    80
    Thanked 4,554 Times in 4,518 Posts
    Are you aware of your inconsistency???

    The query string is looking for "textMessage" but the field in the <form> is named "txtMessage" (missing the "e" in "text").
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    New Coder
    Join Date
    Oct 2010
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile

    Thanks....friend...
    You have solved my important problem....
    Thank you...very much


  •  

    Posting Permissions

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