how to pass input element value to javascript after urlencoding it using php
I've an input text field.
On press enter, i'm performing the following 开发者_Python百科action
function doWork(){
httpObject = getHTTPObject();
if (httpObject != null) {
link = "message.php?nick="+nickName+"&msg="+document.getElementById('msg').value;
httpObject.open("GET", link , true);
httpObject.onreadystatechange = setOutput;
httpObject.send(null);
}
}
What I want is to "urlencode" the value.
How should I do that??
Use the JavaScript function encodeURIComponent
link = "message.php?nick="+nickName+"&msg="+encodeURIComponent(document.getElementById('msg').value);
Just wrap the value with "escape" as in:
link = "message.php?nick="+nickName+"&msg="+escape(document.getElementById('msg').value);
精彩评论