Show/Hide HTML

Hi

I want to show a button that display "Show" initially.
When click on it, the hidden html text will display & the button will show "hide".

Now when user click "hide", the shown html text will be hidden again.

Pls help.

Thanks & Rgds
Heng03

heng03Asked:
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.

boonlengCommented:
<html>
<head>
<script>
function change(button) {
  var element = document.getElementById('message');

  if (button.value == 'show') {
    button.value = 'hide';
    element.style.visibility = 'visible';
  } else {
    element.style.visibility = 'hidden';
    button.value = 'show';
  }
}
</script>

</head>
<body>
<form>
<input type="button" value="show" onclick="change(this)">
<div id="message" style="visibility:hidden">Message Here</div>
</form>

</body>
</hrml>
0

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
archrajanCommented:
<script language="JavaScript" type="text/javascript">

    function change_button(this_button)
    {
        document.getElementById(this_button).value = (document.getElementById(this_button).value == 'Hello')? 'World' : 'Hello';
    }

</script>

<form action="javascript:void(0);">
    <input type='submit' name'button' value='Hello' id='this_button' onclick='change_button("this_button");' />
</form>
0
heng03Author Commented:
Hi

I increase point to 75.
I would like both you to share.

Thanks & Rgds
Heng03
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

heng03Author Commented:
Hi boonleng

how to suppress the spaces (lines) when invisible mode ?
That is, my messages contains many lines.

Thanks & Rgds
Heng03
0
boonlengCommented:
Use "display" instead of "visibility".

if (button.value == 'show') {
  button.value = 'hide';
  element.style.display = 'block';
} else {
  element.style.display = 'none';
  button.value = 'show';
}

<div id="message" style="display: none"> Message Here</div>
0
heng03Author Commented:
Hi Boonleng

It do not work for style="display:none".
Why ?

Thanks & Rgds
Heng03
0
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
HTML

From novice to tech pro — start learning today.