-3

By clicking image "imgAdd", I want to set visibility of div "divAddCustomerInfo" to true by using JavaScript. But click on image isn't working. I think that is because JavaScript isn't working. Anyone can help? Yhanks in advance.

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
 <script type="text/javascript">
    function imgAdd_click() {
        document.getElementById("divAddCustomerInfo").style.visibility = 'visible';
    }
</script>
<div id="divCustomerBody" style="margin-left:300px; margin-top:50px;">
    <h1>Customer</h1>
    <hr style="color:gray; width:900px; margin-left: 0px;" />
    <br />
    <div id="divOperationSymbol" style="height:100px; width:900px; ">

        <div id="divAddition" onclick="divAddition_click()" style="height:100px; float:left; width:300px; " >
            <img id="imgAdd" onclick="imgAdd_click()" src="001446-3d-transparent-glass-icon-media-a-media35-add.png" style="height:70px; width:70px; display:block; margin-left:auto; margin-right:auto;" />
            <label id="lblAdd" onclick="lblADD_click()" style="color: #a6a6a6; margin-left:100px;">Add Customer</label>
        </div>

    </div>
</div>
    <div id="divAddCustomerInfo" style="visibility: hidden; margin-left:300px; margin-top:50px;">

</div>

waqar ahmed somra
  • 141
  • 1
  • 5
  • 16

3 Answers3

1

Change the following

<div id="divAddCustomerInfo" runat="server" visible="false" style="margin-left:300px; margin-top:50px;">

Into

<div id="divAddCustomerInfo" runat="server" style="visibility:hidden;margin-left:300px; margin-top:50px;">
Maths RkBala
  • 2,207
  • 3
  • 18
  • 21
0

Update the following portion as

<div id="divAddition" onclick="divAddition_click()" style="height:100px; float:left; width:300px; " >
            <img id="imgAdd" onclick="imgAdd_click()" src="001446-3d-transparent-glass-icon-media-a-media35-add.png" style="height:70px; width:70px; display:block; margin-left:auto; margin-right:auto;" />
            <label id="lblAdd" onclick="lblADD_click()" style="color: #a6a6a6; margin-left:100px;">Add Customer</label>
        </div>
Sasikumar
  • 863
  • 5
  • 9
-2

It is working version of your code (see below): Your mistakes:

  • the absence of brackets in onclick
  • the absence visibility: hidden; in div id="divAddCustomerInfo"

<div id="divCustomerBody" style="margin-left:300px; margin-top:50px;">
    <h1>Customer</h1>
    <hr style="color:gray; width:900px; margin-left: 0px;" />
    <br />
    <div id="divOperationSymbol" style="height:100px; width:900px; ">

        <div id="divAddition" onclick="divAddition_click()" style="height:100px; float:left; width:300px; " >
            <img id="imgAdd" onclick="imgAdd_click()" src="http://www.ipac.caltech.edu/2mass/gallery/antennae.jpg" style="height:70px; width:70px; display:block; margin-left:auto; margin-right:auto;" />
            <label id="lblAdd" onclick="lblADD_click()" style="color: #a6a6a6; margin-left:100px;">Add Customer</label>
        </div>

    </div>
</div>
<div id="divAddCustomerInfo" runat="server"   style="margin-left:300px; margin-top:50px; visibility:hidden">
    Text
</div>

function imgAdd_click() {
    document.getElementById("divAddCustomerInfo").style.visibility = 'visible';
}
Kas Elvirov
  • 7,394
  • 4
  • 40
  • 62