Java Script - Toggle a checkbox by clicking on an image

feesu
feesu used Ask the Experts™
on
Hi Experts,

I have got the following image and check box. I want - on client side- if the user clicks on the image to toggle the check box.
Please find below my code:
<script language ="javascript" type ="text/javascript"  >
function WrapGiftClick()
{
    var obj = document.getElementById('<% =chk_GiftWrap.ClientID %>');
    obj.value = (obj.value != true ? true : false );

}

</script>

...



            <td align="right" valign="top">
                <table border="0" cellpadding="0" cellspacing="0" width="220">
                    <tr>
                        <td>
                            <img id="img_giftWrap" onclick="WrapGiftClick" src="images/giftWrap1.jpg" style="width: 43px; height: 45px" /></td>
                        <td width="5">
                        </td>
                        <td>
                            <asp:CheckBox ID="chk_GiftWrap" runat="server" CssClass="text" Text="Gift wrap the items purchased"
                                TextAlign="Left" /></td>
                    </tr>
                </table>
            </td>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
leakim971Multitechnician
Top Expert 2014

Commented:
Hello feesu,

Replace :
<img id="img_giftWrap" onclick="WrapGiftClick" src="images/giftWrap1.jpg" style="width: 43px; height: 45px" />

By :
<img id="img_giftWrap" onclientclick="WrapGiftClick" src="images/giftWrap1.jpg" style="width: 43px; height: 45px" />

Regards
HonorGodSoftware Engineer

Commented:
it needs to be:

onclick='WrapGiftClick()'
Software Engineer
Commented:
and

obj.checked = !obj.checked;

within the routine
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

leakim971Multitechnician
Top Expert 2014
Commented:
Correction :

Replace :
<img id="img_giftWrap" onclick="WrapGiftClick" src="images/giftWrap1.jpg" style="width: 43px; height: 45px" />

By :
<img id="img_giftWrap" onclientclick="WrapGiftClick();" src="images/giftWrap1.jpg" style="width: 43px; height: 45px" />

leakim971Multitechnician
Top Expert 2014

Commented:
Forget my comments, HonorGod is right (not asp element...)
leakim971Multitechnician
Top Expert 2014

Commented:
Thanks for the points!
HonorGodSoftware Engineer

Commented:
Thanks for the grade & points.

Good luck & have a great day.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial