0

I have a Asp.net TextBox with TextMode="Password": <asp:TextBox ID="txtAuthPwd" runat="server" TextMode="Password"/>

I need to get the value of this TextBox from the javascript

<script type="text/javascript">
    function someFunc() {
        var pwd = document.getElementById("<%=txtAuthPwd.ClientID%>").value;
    }
</script>

But the value is always empty. Please help...

2
  • are you sure about txtAuthPwd.ClientID ?? check the source code of the html Commented Oct 14, 2011 at 22:58
  • Yup, @salahy is right- your code should work. Are you sure someFunc() is getting called? Any javascript errors? Commented Oct 15, 2011 at 4:46

1 Answer 1

2

Please check my code as below and it's working.

<asp:TextBox ID="txtPwd" TextMode="Password" runat="server"></asp:TextBox><br />
<asp:Button ID="btnSubmit" Text="Click" runat="server" OnClientClick="return test();" />


<script language="javascript" type="text/javascript">
    function test() {
        var pwd = (document.getElementById("<%= txtPwd.ClientID %>").value);
        alert(pwd);
        return false;
    }
</script>
Sign up to request clarification or add additional context in comments.

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.