简体   繁体   中英

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

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.

如果我理解正确,你只是想设置值,只需使用:

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

正确的方法是:

document.getElementById("<%= monthlyAmount.ClientID %>").value = "test";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM