dshrenik
asked on
document.getElementById
I am trying to get the reference to an HTML textbox using:
var tb1 = document.getElementById(id );
tb1.style.display = "none";
But, this does not seem to work.
Please let me know what I might be missing. Thanks!
var tb1 = document.getElementById(id
tb1.style.display = "none";
But, this does not seem to work.
Please let me know what I might be missing. Thanks!
ASKER
id is a variable that stores the actual ID
wait the dom
if you've asp.net use ClientID : http://beyondrelational.com/blogs/hima/archive/2010/07/16/all-about-client-id-mode-in-asp-net-4.aspx
var tb1 = document.getElementById("< %= Textbox1.ClientID %>");
tb1.style.display = "none";
http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientid.aspx
window.onload = function() {
var tb1 = document.getElementById("someid");
tb1.style.display = "none";
}
if you've asp.net use ClientID : http://beyondrelational.com/blogs/hima/archive/2010/07/16/all-about-client-id-mode-in-asp-net-4.aspx
var tb1 = document.getElementById("<
tb1.style.display = "none";
http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientid.aspx
ASKER
Using Firebug, this is the source for the HTML element:
<input id="id_1dropdown_0*p_0" class="parameterStyle" type="text" onchange="checkParameter1(this);" name="id_1dropdown_0*p_0" style="border-left: 1px solid grey; border-right: 1px solid grey; border-width: 1px; border-style: solid; border-color: grey;">
ASKER
I can't do this on "window.onload ". I need to do it after the page loads
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you're trying to use 'id' as a variable name, I suggest you change it to something else because that has a specific meaning already. While it is not a reserved word, I would use a variation of it like 'id1' or something that would not be confused with the HTML attribute 'id'.
Are you sure that 'id' contains a valid value? Your syntax looks ok. http://www.w3schools.com/jsref/prop_style_display.asp
Are you sure that 'id' contains a valid value? Your syntax looks ok. http://www.w3schools.com/jsref/prop_style_display.asp
The asterisk is not a legal character in the id. id="id_1dropdown_0*p_0" From W3C:
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
with a dropdown : http://jsfiddle.net/FvPK5/1/
ASKER
It is not a dropdown. It is a textbox (the id is misleading).
ASKER
I am able to retrieve the textbox with this line of code:
var tb1 = document.getElementById(id );
I can display its value by saying:
alert(tb1.value);
However, this is not working:
tb1.style.display = "none";
var tb1 = document.getElementById(id
I can display its value by saying:
alert(tb1.value);
However, this is not working:
tb1.style.display = "none";
try with an alert after :
tb1.style.display = "none";
alert("do you still see it really before clicking OK?");
ASKER
It was my mistake. It actually works. Thanks!
If possible, please answer this question:
https://www.experts-exchange.com/questions/27314630/Change-the-visibility-of-an-HTML-textbox.html
If possible, please answer this question:
https://www.experts-exchange.com/questions/27314630/Change-the-visibility-of-an-HTML-textbox.html
var tb1 = document.getElementById("i
tb1.style.display = "none";
http://www.w3schools.com/jsref/dom_obj_style.asp