最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to set the value of a text box with javascript on an ASP.NET webform - Stack Overflow

programmeradmin4浏览0评论

so in a form I have the following control:

<asp:TextBox runat="server" ID="monthlyAmount" ClientIDMode="Static"/>

The ClientIDMode Static is because a master page is in use.

I then have this Button:

<input type="button" id="calculate" onclick="AutoFillEstimate()" value="Calculate Estimate" />

Wired to this Script:

<script type="text/javascript">
    function AutoFillEstimate() {
        document.getElementById("monthlyAmount").nodeValue = "test";
    }
</script>

I feel like I'm just using nodeValue instead of what I should be using, but I have no idea where to look for reference on these things.

so in a form I have the following control:

<asp:TextBox runat="server" ID="monthlyAmount" ClientIDMode="Static"/>

The ClientIDMode Static is because a master page is in use.

I then have this Button:

<input type="button" id="calculate" onclick="AutoFillEstimate()" value="Calculate Estimate" />

Wired to this Script:

<script type="text/javascript">
    function AutoFillEstimate() {
        document.getElementById("monthlyAmount").nodeValue = "test";
    }
</script>

I feel like I'm just using nodeValue instead of what I should be using, but I have no idea where to look for reference on these things.

Share Improve this question asked Mar 15, 2013 at 19:23 FirosoFiroso 6,68510 gold badges50 silver badges93 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 13

If I understand you correctly, you are just trying to set the value, just use:

document.getElementById("monthlyAmount").value = "test";

The correct way to do this is:

document.getElementById("<%= monthlyAmount.ClientID %>").value = "test";
发布评论

评论列表(0)

  1. 暂无评论