Click here to Skip to main content
15,901,283 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all!
I am trying to display a hidden textbox through javascript. I've tried doing that like this:
JavaScript
document.getElementById('<%= banknametxt.ClientID %>').style.display="block";

It won't work and shows an exception 'Object Required '.

Can any one please help me?

Thanks in advance!
Posted
Updated 29-Apr-11 1:22am
v2

This error means the element you are trying to access is not present on the page. So,
a) either you have used wrong id of the textbox in the JavaScript. Or,
b) it seems you have set the visibility of the textbox to false. In ASP.NET if you set visible property of a control to false, the control is not at all rendered. You should rather use CSS and set the display style of the element (textbox) to "none".

You can check the page source to find if the element is rendered or not.

Hope this helps!
 
Share this answer
 
Dont use Visible=false property of textbox
u can set textbox property display:none in source code
After that on button click use display:block as u have written
here is sample how u can do this
XML
<style type="text/css">
.huy
{
display:none;
}
</style>
  <script type="text/javascript">
  function showtextbox()
  {
  document.getElementById("TextBox1").style.display="block";
  return false;
  }
  </script>


XML
<asp:Button ID="Button1" runat="server" OnClientClick="return showtextbox();" Text="dsd"
            onclick="Button1_Click" />

        <asp:TextBox ID="TextBox1"  CssClass="huy" runat="server"></asp:TextBox>
 
Share this answer
 
v2
did you try to debug? 'Object Required' means that it could not find the element you tried to look for in the DOM.
 
Share this answer
 
Is that an error you are receiving when the page is shown in the browswer or is it an error at compilation time?
If it is during compilation time then banknametxt isn't a reference to the textbox. If it is in the browser try to separate the steps to assist you in debugging:

JavaScript
var element  = document.getElementById('<%= banknametxt.ClientID %>')
alert(element);
var styleEle = element.style;
alert(styleEle);
stlyeEle.display = "block";
alert(styleEle.display);


Now you'll see how far execution gets by counting the alerts you see.

Best Regards,

-MRB
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900