• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1629
  • Last Modified:

Javascript Referencing Invisible Text Box?

I have some javascript that attempst to reference an invisible field on the page which generates an error.
What is the best approach to fixing this?

...javascript
var iNotVisible = parseInt(document.getElementById('ctl00_ContentPlaceHolder1_tbNotVisible').value);

...textbox
<asp:TextBox ID="tbNotVisible" runat="server" Visible="False" Height="7px" Width="66px"></asp:TextBox><br />


0
ChiBella
Asked:
ChiBella
1 Solution
 
davisnwCommented:
It looks like you are using ASP.NET.  If this is correct, then you will not be able to reference the textbox via javascript if you set visible to false.  Here is why:

When you set Visible="False" in the asp.net page, this is processed on the server side, and the control will never be rendered as html.

What you can do however, is set Visible="true" and then use CSS to hide the element.  That way, the server control will be rendered as html and you will be able to access it via javascript.  So something like:

<asp:TextBox ID="tbNotVisible" runat="server" Visible="true" Height="7px" Width="66px" style="display:none"></asp:TextBox><br />
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now