JavaScript - show one div and hide another from form checkbox

I have a form checkbox that I would like to use to hide one table and display another when checked and vise versa.
if checkbox is ticked hide table with id showmessage and display table with id showbuttons.

 <input name="pickup_order" type="checkbox" id="pickup_order" value="Y">
 
 <table id="showmessage" style="visibility:visible" width="737" border="0" align="center" cellpadding="5" cellspacing="5">

 <table id="showbuttons" style="visibility:hidden" width="737" border="0" align="center" cellpadding="5" cellspacing="5">

 Thanks in advance for your comments.
sabecsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971MultitechnicianCommented:
Use something like :

function $(id,s) {
    document.getElementById(id).style.visibility=s
}

if(this.checked) {
   $('showmessage','hidden');
   $('showbuttons','visible');
}
else{
   $('showmessage','visible');
   $('showbuttons','hidden')
}

Test page :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<input name="pickup_order" type="checkbox" id="pickup_order" value="Y" onclick="function $(id,s){document.getElementById(id).style.visibility=s};if(this.checked){$('showmessage','hidden');$('showbuttons','visible')}else{$('showmessage','visible');$('showbuttons','hidden')}">
<table id="showmessage" style="visibility:visible" width="737" border="0" align="center" cellpadding="5" cellspacing="5"><tr><td>Table 1</td></tr></table>
<table id="showbuttons" style="visibility:hidden" width="737" border="0" align="center" cellpadding="5" cellspacing="5"><tr><td>Table 2</td></tr></table>
</body>
</html>

Open in new window

leakim971MultitechnicianCommented:
The same logic :

      function swapTable(checkbox) {
            if(checkbox.checked) {
                  document.getElementById('showmessage').style.visibility = 'hidden';
                  document.getElementById('showbuttons').style.visibility = 'visible';
            }
            else{
                  document.getElementById('showmessage').style.visibility = 'visible';
                  document.getElementById('showbuttons').style.visibility = 'hidden';
            }
      }

Test page :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
	function swapTable(checkbox) {
		if(checkbox.checked) {
			document.getElementById('showmessage').style.visibility = 'hidden';
			document.getElementById('showbuttons').style.visibility = 'visible';
		}
		else{
			document.getElementById('showmessage').style.visibility = 'visible';
			document.getElementById('showbuttons').style.visibility = 'hidden';
		}
	}
</script>
</head>
<body>
<input name="pickup_order" type="checkbox" id="pickup_order" value="Y" onclick="swapTable(this);">
<table id="showmessage" style="visibility:visible" width="737" border="0" align="center" cellpadding="5" cellspacing="5"><tr><td>Table 1</td></tr></table>
<table id="showbuttons" style="visibility:hidden" width="737" border="0" align="center" cellpadding="5" cellspacing="5"><tr><td>Table 2</td></tr></table>
</body>
</html>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sabecsAuthor Commented:
Thanks leakim971.
leakim971MultitechnicianCommented:
You're welcome! Thanks for the points!

Don't know if it apply to you, but you may use : style.display instead style.visibility
http://protocolsofmatrix.blogspot.com/2007/12/difference-between-visibility-display.html
http://webdesign.about.com/od/css/f/blfaqhidden.htm
http://ntt.cc/2010/04/13/tips-whats-the-difference-between-display-and-visibility-properties-in-css.html


function swapTable(checkbox) {
            if(checkbox.checked) {
                  document.getElementById('showmessage').style.display = 'none';
                  document.getElementById('showbuttons').style.display = 'block';
            }
            else{
                  document.getElementById('showmessage').style.display = 'block';
                  document.getElementById('showbuttons').style.display = 'none';
            }
      }

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.