Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q672 How can I pass a string value which is separated by spaces using the locations search string?

You are here: irt.org | FAQ | JavaScript | Link | Q672 [ previous next ]

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>

©2018 Martin Webb