|
Q672 How can I pass a string value which is separated by spaces using the locations search string?
irt.org | Knowledge Base | JavaScript | Link | Q672 [ previous next ]
Q672 How can I pass a string value which is separated by spaces using the locations search string?
Try:
<SCRIPT LANGUAGE="JavaScript"><!--
var message = "This is my message";
location.href = 'sendmsg.html?Sentmessage=' + escape(message);
//--></SCRIPT>
|
or:
<SCRIPT LANGUAGE="JavaScript"><!--
var message = "This+is+my+message";
location.href = 'sendmsg.html?Sentmessage=' + message;
//--></SCRIPT>
|
And then in the sendmsg.html file replace any + with space:
<SCRIPT LANGUAGE="JavaScript"><!--
function replace(string,text,by) {
// Replaces text with by in string
var strLength = string.length, txtLength = text.length;
if ((strLength == 0) || (txtLength == 0)) return string;
var i = string.indexOf(text);
if ((!i) && (text != string.substring(0,txtLength))) return string;
if (i == -1) return string;
var newstr = string.substring(0,i) + by;
if (i+txtLength < strLength)
newstr += replace(string.substring(i+txtLength,strLength),text,by);
return newstr;
}
alert(replace(location.search.substring(1),'+',' '));
//--></SCRIPT>
|
|
|
Copyright © 1996-2009 irt.org, All Rights Reserved.