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
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!
Originally Posted by
dubmecrazy
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.
Where used, return should be executed unconditionally and always as the last statement in the function.
That's my signature, it's not part of the damn post!
Originally Posted by
newjavascript
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.
Where used, return should be executed unconditionally and always as the last statement in the function.
That's my signature, it's not part of the damn post!
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
Forum Rules
Bookmarks