Link to home
Start Free TrialLog in
Avatar of Mike Eghtebas
Mike EghtebasFlag for United States of America

asked on

aps 4... javascript... debug

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";
                    }
                }
            }
        </script>

Open in new window



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">
                    &nbsp;</td>
                <td class="style7">
                    <asp:CheckBox ID="chkAddComment" runat="server" Text="Add Comment"  />
                    
                </td>
                <td class="style5">
                    &nbsp;
                </td>
            </tr>
            <tr id="CommentRow" class="style10">
                <td class="style10">
                    Comment:</td>
                <td class="style7" colspan="2">
                    <asp:TextBox ID="txtComment" runat="server" Columns="40" Rows="5" Wrap="True" 
                        TextMode="MultiLine"></asp:TextBox>
                </td>
            </tr> 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike Eghtebas

ASKER

The solution works fine. Thank you.