12

EDIT: Since the question has became quite popular I will fix the problem so it will be working code example. The original problem is still listed, But the code works.

i am trying to show a div after pressing a button but this wont work, any idea why is that?

<form action="insert.php" method="POST" align="right" id="post_form">
<input type="button" value="click me" onClick="show()">
<div id="show_button">  fdsfds </div><br>
</form>

#show_button{
 visibility:hidden;
}

function show(){
  // alert("cheked the button - worked");
  document.getElementById("show_button").style.visibility= 'visible' ;
}
antonpuz
  • 2,947
  • 4
  • 21
  • 45

4 Answers4

19

Change your CSS to:

#show_button{
 display: none
}

And you in your javascript:

function show(){
  //alert("cheked the button - worked");
  document.getElementById('show_button').style.display= 'block' ;
}
Dragos Rizescu
  • 3,220
  • 5
  • 29
  • 41
4

Typo error change it document.getElementById(show_button) to document.getElementById("show_button")

function show(){
  document.getElementById("show_button").style.visibility= "visible" ;
}
Tamil Selvan C
  • 19,232
  • 12
  • 49
  • 68
1

Try this :

function show(){
  //alert("cheked the button - worked");
  document.getElementById("show_button").style.visibility= "visible" ;
}

or

function show(){
  //alert("cheked the button - worked");
  document.getElementById(show_button).style.display= "inline" ;
}
Arup Rakshit
  • 113,563
  • 27
  • 250
  • 306
0

document.getElementById(show_button) -: syntax error, Missing quotes " " !

Tamil Selvan C
  • 19,232
  • 12
  • 49
  • 68
sakthi
  • 929
  • 5
  • 18