Avatar of Mike Eghtebas
Mike Eghtebas
Flag 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";

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">
                <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" 

Open in new window


Avatar of undefined
Last Comment
Mike Eghtebas

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Mike Eghtebas

The solution works fine. Thank you.
Mike Eghtebas

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck