开发者

how to pass input element value to javascript after urlencoding it using php

开发者 https://www.devze.com 2023-01-20 14:00 出处:网络
I\'ve an input text field. On press enter, i\'m performing the following 开发者_Python百科action

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

精彩评论

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