开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜