开发者

How to encode txt.value

I am passing a string to a javascript through call by reference. The s开发者_开发知识库tring is a text retrieved from a textarea field. The problem is that a single word is retrieved properly, but when i send multiple text it shows a problem. the sample code is like this in an html file:

<input type=button onclick="send(txt.value,123,456)">

How to encode txt.value in this case


It depends on what send expects. generally speaking since it looks like you are calling a function you don't need any encoding.

maybe if you will provide some more code we can better help you.


Try this one:

ASPX:

<asp:TextBox ID="txtFirst" runat="server" Text="First"></asp:TextBox><br />
<input type="button" onclick="send(document.getElementById('txtFirst').value,123,456)" value="Click">

JAVASCRIPT:

function send(txtValue,obj1,obj2)
{
    alert(txtValue);
    return false;
}


First of all, txt.value is IE only code. Use document.getElementById which is cross browser.

Second, the concept itself is working (proof of concept) so something else in your code is causing the problem.

Post your real code and the full function and we'll see.


A textarea tag is not a simple input, so you can't get its "value" from txt.value. You have to get what is between the tags. Personally I do this with Jquery like this

<script type="text/javascript" src="jquery.js"></script>


function doSend()
{
    var txtvalue=$('#textareaID').text();
    send(txtvalue,123,456);
}

<input type=button onclick="doSend">
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜