开发者

javascript not storing value in textbox in asp

开发者 https://www.devze.com 2023-03-10 14:37 出处:网络
I am using javascript in an asp.net page where I am also using html textarea to get the text from users.

I am using javascript in an asp.net page where I am also using html textarea to get the text from users.

I want to store that text in the asp:TextBox below and set the visibility of that textbox to "false".. The problem arises as I use the hidden textbox to store the value , my javascript is not working, and as I set the visibility to "true" it starts working again. but i didn't want to show textbox.. I included the textbox as:

 <asp:TextBox ID="txtboxhead" runat="server" Visible="false"></asp:TextBox>

and i use javascript as:

document.getElementById('txtareahead').readO开发者_如何学JAVAnly = true;
text = document.getElementById('txtareahead').value;
document.getElementById('<%= txtboxhead.ClientID %>').value = text;

how this problem can be solved.. please help me out..


The reason your javascript can not access the textbox when the visibility is set to false is because it simply doesn't exist.

This is because the server is processing the request and because it is set to false it doesn't render it to the page. What you want to do is to change the style of the textbox so it is hidden.

Eg below,

<div style="display:none">
<asp:TextBox ID="txtboxhead" runat="server"></asp:TextBox>
</div>

This way your script will still run and the users will not be able to see the textbox.

HTH


Sounds like what you really want is an <asp:HiddenField> it won't display on the page, but you'll be able to change its contents using javascript.

0

精彩评论

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

关注公众号