troubleshooting Question

aps 4... javascript... debug

Avatar of Mike Eghtebas
Mike EghtebasFlag for United States of America asked on
3 Comments1 Solution330 ViewsLast Modified:
When chkAddComment = True or false, txtComment show/hide using:

        <script type="text/javascript">
            window.onload = function () {

                document.getElementById("<%= chkAddComment.ClientID %>").onchange = function () {
                    var chkAddComment = document.getElementById("<%= chkAddComment.ClientID %>")

                    if (this.checked) {
                        document.getElementById("CommentRow").style.display = "block";
                    } else {
                        document.getElementById("CommentRow").style.display = "none";

This works fine except when the page first loads. When the page first loads and the default value of chkAddComment is false, txtComment remains visible. But when user checks chkAddComment on and off one round txtComment disapears (as expected).

Question: How can I change my code where the txtComment wouldn't show on first time page load?

I suppose I could set txtComment invisible. If so, then I can I make it vsible via the above javascript code?

This is the partial html for ID="chkAddComment" and ID="txtComment":

            <tr id="chkcommentRow">
                <td class="style10">
                <td class="style7">
                    <asp:CheckBox ID="chkAddComment" runat="server" Text="Add Comment"  />
                <td class="style5">
            <tr id="CommentRow" class="style10">
                <td class="style10">
                <td class="style7" colspan="2">
                    <asp:TextBox ID="txtComment" runat="server" Columns="40" Rows="5" Wrap="True" 
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros