4

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.

2 Answers 2

13

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

document.getElementById("monthlyAmount").value = "test";
Sign up to request clarification or add additional context in comments.

4 Comments

You mean in visual studio? There isn't a whole lot of support for intellisense with javascript, I wouldn't rely on it at all.
Honestly, depending on what you're doing.. I would use Stackoverflow or google...
@Firoso Mozilla has a very good reference developer.mozilla.org/en-US/docs/JavaScript
This won't work. The id of the asp control is not the id you give it. The id represents the hierarchy of controls. You want to use Client ID property.
4

The correct way to do this is:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.