Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2010
    Posts
    46
    Thanks
    1
    Thanked 1 Time in 1 Post

    Increment Textbox using Javascript

    Trying to increment Textbox3 using Javascript in ASP.net.

    Not sure how to input a textbox value to count:
    document.getElementById("<%=TextBox3.ClientID%>").value

    Here is the code:

    Code:
    <script type="text/javascript">
        function inc() {
            var count = document.getElementById("<%=TextBox3.ClientID%>").value;
            if (count = "") { count = 0; }
            document.getElementById("<%=TextBox3.ClientID%>").value = count + 1;
        }
    </script>
    Last edited by Philosophaie; 03-01-2013 at 02:04 PM.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,084
    Thanks
    23
    Thanked 593 Times in 592 Posts
    If that's not working for you, you might need to cast 'count' as a number.
    Number(count)+1

    Also the line
    Code:
    if (count = "") { count = 0; }
    is not an if statement, you need '==' not '=' to make it an if. What you have sets the variable count equal to zero and your out come for the js code should be the number one in the text box.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •