www.webdeveloper.com
Results 1 to 4 of 4

Thread: How to get textbox value

  1. #1
    Join Date
    Feb 2013
    Posts
    4

    Question How to get textbox value

    Dear All,

    My textbox ID is TextBox1, How to get its value?

    I tried:

    var mytext = document.getElementById("TextBox1");
    or
    var mytext = document.getElementById("TextBox1").value;

    no luck

  2. #2
    Join Date
    Jan 2005
    Location
    Los Angeles
    Posts
    8
    I think you just helped me figure out my problem!

    I'm not sure, but I think the variable has to be the same as the id:

    var TextBox1 = document.getElementById("TextBox1").value;

    I could be wrong about that. Also, what I have seen is single quotes, not double so try:

    var TextBox1 = document.getElementById('TextBox1').value;

    Not sure if that makes a difference or not either.

    I'm gonna try changing my var names now to see if it works!

    Good luck!

  3. #3
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by newjavascript View Post
    var mytext = document.getElementById("TextBox1").value;
    Is correct.

    Don't execute the code until the element is rendered.

    Use the error console.

    If it still doesn't work, post your entire code including HTML.

  4. #4
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by dubmecrazy View Post
    I think you just helped me figure out my problem!

    I'm not sure, but I think the variable has to be the same as the id
    It certainly does not have to be the same. In fact if (for whatever reason) you're using a global variable, it should not match the ID of any element, due to IDs being treated in some cases as global variables.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles