Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide Form in HTML using Javascript

I have been trying to hide a form after the submit button is clicked. I have googled and followed some but they seem to be not working for me.

This is my code:

HTML:

<div id="wrapper">
<form name="regForm" id="regForm" action="indexSave.php" method="post">

<table width="100%" border="0">
   <tr>
    <td colspan="2"> <center> Registration Form </center> </td>
   </tr>
   <tr>
    <td width="23%">&nbsp; Name</td>
    <td width="33%">&nbsp; <input type="text" name="name"  /> </td>
   </tr>
   <tr>
    <td>&nbsp; Email Address</td>
    <td>&nbsp;  <input type="text" name="email"  /></td>
   </tr>
   <tr>
    <td>&nbsp; Contact Number</td>
    <td>&nbsp;  <input type="text" name="number"  /></td>
   </tr>
   <tr>
    <td>&nbsp; Message</td>
    <td width="100">&nbsp; <textarea name="msg"> </textarea> </td>
   </tr>
   <tr>
    <td>&nbsp;  <input onclick="myClick()" name="submit" id="submit" type="submit" value="Submit"  /> </td>
    <td>&nbsp;</td>
  </tr>
</table>
</form>
</div>

And my Javascript:

<script type="text/javascript">
    function myClick() 
    {
        var me = document.getElementById("wrapper").visibility="false";
    }
</script>

I also tried this (from this link )

var me = document.getElementById("regForm").style.display="none";

Please help me figure out what's wrong?

like image 869
LadyWinter Avatar asked Mar 05 '26 12:03

LadyWinter


1 Answers

You simply need:

function myClick(){
     var form = document.getElementById("regForm");
     form.style.display = "none";
}

DEMO

like image 187
Gaurang Tandon Avatar answered Mar 07 '26 00:03

Gaurang Tandon