JavaScript Show/Hide

  • Thread starter Thread starter Wee
  • Start date Start date

Wee

Wee

Associate
Joined
25 Apr 2006
Posts
130
Location
Scotland
I've only just started to use JavaScript, but I was attempting to create a simple function that would allow a user to click on a link were it would show or hide a DIV. I managed to get the DIV to show when the link it clicked, but it when it's clicked again it doesn't want to hide.

Code:
var choice = 'hidden';

function showLogin(choice) {

  if (choice == 'hidden'){
  document.getElementById('login').style.display='block';
  var choice = 'display';}

else if (choice == 'display'){

  document.getElementById('login').style.display='none';
  var choice = 'hidden';}}

Here's the code on the HTML link.

Code:
<a href="javascript:showLogin(choice);">

Anyone got any pointers were I could be going wrong?
 
Last edited:
Cheers for the help. Will give it a shot as soon as my Uni's VPN connection decides to start working again. :)
 
Back
Top Bottom