...

View Full Version : Displaying the Query String in the TextField



Umesh123
12-27-2010, 01:08 PM
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....:)

Old Pedant
12-27-2010, 07:43 PM
What is a "TextField" control???

There is no such thing in HTML. Do you mean a <textarea>??

Umesh123
12-28-2010, 04:50 AM
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....
:)

Old Pedant
12-28-2010, 05:47 AM
Then you could just do

document.forms[0].nameOfTextArea.value = theParsedQueryStringInfo;

You would need to put a newline character ("\n") between each line of information.

Umesh123
12-28-2010, 12:48 PM
Then you could just do

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>

Old Pedant
12-28-2010, 09:04 PM
Man, did you WAY overcomplicate that!

I *THINK* this is all you need:


<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:


queryTest.html?textSender=joe+dimaggio&textMessage=Now+is the+time%3f%0AGive+up%3f

And it seemed to me that it worked.

Old Pedant
12-28-2010, 09:06 PM
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").

Umesh123
12-29-2010, 05:03 AM
Thanks....friend...
You have solved my important problem....
Thank you...very much



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum