checkbox onclick show

debbieau1
debbieau1 used Ask the Experts™
on
I have a checkbox

<input name="mycheck" type="checkbox" value="1" id="mycheck" />

I want to call a hideinfo function  (if it is not selected)   or showinfo function (if checkbox value is selected).  I need to call a function, not show a div as I am using this with canvas.

So it should be if checkbox is selected (has 1) then run showinfo()
 if checkbox is not selected  then run hideinfo()
Comment
Watch Question

Do more with

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

Commented:
<input name="mycheck" type="checkbox" value="1" id="mycheck" onclick="if(this.checked) showinfo();else hideinfo();" />

Open in new window

Erdinç Güngör ÇorbacıPHP Development Team Leader

Commented:

if(document.getElementById('mycheck').checked=true) showinfo();
else hideinfo();

Open in new window

Multitechnician
Top Expert 2014
Commented:
if you want to reuse (multiple checkboxes) :
<input name="mycheck"  type="checkbox" value="1" id="mycheck"  onclick="decide(this.checked)" />
<input name="mycheck0" type="checkbox" value="1" id="mycheck0" onclick="decide(this.checked)" />
<input name="mycheck1" type="checkbox" value="1" id="mycheck1" onclick="decide(this.checked)" />
<input name="mycheck2" type="checkbox" value="1" id="mycheck2" onclick="decide(this.checked)" />

and 

<script>
function decide(boo) {  if(boo) showinfo();else hideinfo(); }
</script>

Open in new window

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!

Erdinç Güngör ÇorbacıPHP Development Team Leader
Commented:
if you want that check box work in realtime leakim971's suggestion is the solution . But if you set or unset checkbox according to a value with php while page is being prepared then use the code i've sent at the bottom of your page to show or hide division .

btw for a checkbox practice take a look at http://www.irt.org/articles/js027/

Author

Commented:
Thanks

Author

Commented:
Thanks heaps erdincgc

Very helpful.  

I can use both solutions in what I am doing.  Thanks again

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