How can I hide/show a form when a button is clicked using javascript? -


i need correct code. have watched video youtube in video, use checkbox instead of button. i'm having problem if else statement of javascript. have checked previous post have same problem couldn't find 1 can solve problem. please me. thank much.

<!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>     <link href="css/tabmenu.css" rel="stylesheet" type="text/css" />      <style>         .hidden {             display:none;}     </style>     <script type="text/javascript">         function showhide()         {             var button = document.getelementbyid("butt");             var hiddeninput = document.getelementbyclassname("hidden");                  if(button.click)                 {                     hiddeninput.style.display = "block";                 }                 else                 {                     hiddeninput.style.display = "none";                 }         }      </script>      </head>      <body>     <div id="navbar">     <div id="holder">      <ul>     <li><a href="employee.php" id="onlink">employer database</a></li>     <li><a href="companypresence.php">company presence</a></li>     <li><a href="companypromotion.php">company promotion</a></li>     </ul>        </div><!--end of holder div -->     </div><!--end of navbar div -->      </br>      <p id="p1"><u>employer list</u></p>     </br>       <table width="1345" height="113" border="1" id="table1">       <tr id="tr1">         <th width="46" height="35" scope="col">no.</th>         <th width="93" scope="col">title</th>         <th width="157" scope="col">first name</th>         <th width="171" scope="col">last name</th>         <th width="128" scope="col">position</th>         <th width="130" scope="col">sector</th>         <th width="178" scope="col">company name</th>         <th width="107" scope="col">country</th>         <th width="97" scope="col">email</th>         <th width="78" scope="col">phone</th>         <th width="84" scope="col">action</th>       </tr>       <tr>         <td height="34">&nbsp;</td>         <td>&nbsp;</td>         <td>&nbsp;</td>         <td>&nbsp;</td>         <td>&nbsp;</td>         <td>&nbsp;</td>         <td>&nbsp;</td>         <td>&nbsp;</td>         <td>&nbsp;</td>         <td>&nbsp;</td>         <td>&nbsp;</td>       </tr>       <tr>         <td height="34">&nbsp;</td>         <td>&nbsp;</td>         <td>&nbsp;</td>         <td>&nbsp;</td>         <td>&nbsp;</td>         <td>&nbsp;</td>         <td>&nbsp;</td>         <td>&nbsp;</td>         <td>&nbsp;</td>         <td>&nbsp;</td>         <td>&nbsp;</td>       </tr>     </table>     <br/>     <input name="addbutton" type="button" value="add employer" id="butt" onclick="showhide()"/>     <br/>     <br/>     <br/>     <form id="form1" action="add_employer.php" method="post" class="hidden">     <p align="left"><u><strong>add employer detail</strong></u></p>     <br/>     <br/>     <table  cellpadding="5" cellspacing="2" align="center">                     <tr>                         <td><strong>title </strong></td>                         <td><strong>:                         <input name="title" value="" type="text" size="50" maxlength="50">                         </strong></td>                     </tr>                     <tr>                         <td><strong>first name </strong></td>                         <td><strong>:                         <input name="first_name" value="" type="text" size="50" maxlength="50">                         </strong></td>                     </tr>                     <tr>                         <td><strong>last name</strong></td>                         <td><strong>:                         <input name="last_name" value="" type="text" size="50" maxlength="50">                         </strong></td>                     </tr>                     <tr>                         <td><strong>position</strong></td>                         <td><strong>:                         <input name="position" value="" type="text" size="50" maxlength="50">                         </strong></td>                     </tr>                     <tr>                         <td><strong>sector</strong></td>                         <td><strong>:                         <input name="sector" value="" type="text" size="50" maxlength="50">                         </strong></td>                     </tr>                     <tr>                         <td><strong>company name</strong></td>                         <td><strong>:                         <input name="company_name" value="" type="text" size="50" maxlength="50">                         </strong></td>                     </tr>                     <tr>                         <td><strong>country</strong></td>                         <td><strong>:                         <input name="country" value="" type="text" size="50" maxlength="50">                         </strong></td>                     </tr>                     <tr>                         <td><strong>email</strong></td>                         <td><strong>:                         <input name="email" value="" type="text" size="50" maxlength="50">                         </strong></td>                     </tr>                     <tr>                         <td><strong>phone</strong></td>                         <td><strong>:                         <input name="phone" value="" type="text" size="50" maxlength="50">                         </strong></td>                     </tr>                     <tr>                         <td><strong>action</strong></td>                         <td><strong>:                         <input name="action" value="" type="text" size="50" maxlength="50">                         </strong>                         <input name="addbutton" type="button" value="add employer"/>                         <input name="clear" type="button" value="clear"/>                         </td>                      </tr>                                 </table>     <br/>     <br/>            </form>        </body>     </html> 

you can target form using id , add remove class show hide form.

<style>         .hidden {             display:none;}      </style>      <script type="text/javascript">         function showhide() {             var hiddeninput = document.getelementbyid("form1");             if (hiddeninput.classlist.contains("hidden")) {                 hiddeninput.classlist.remove("hidden");             }             else {                 hiddeninput.classlist.add("hidden");             }         }      </script> 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -