Home » Php » php – Jquery Button to make visible a form

php – Jquery Button to make visible a form

Posted by: admin July 12, 2020 Leave a comment


I want to ask about how to make a form invisible when a button clicked? So, if I have a button called “Hide” and a form with many button, textbox, etc.

Then when I click “Hide” button, it will hide all form and all things in form such as textbox, button, etc. I have google it but have no result. I accept answer with Jquery, JS, or php language because I’m using that language program.

Example my form is like this:

<form name="myform" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
            <td><input type="text" maxlength="15" name="clientid" /></td>
            <td><input type="submit" name="cariclientid" value="Search" /></td>
            <td width="50px"></td>
            <td><input type="text" maxlength="15" name="orderid" /></td>
            <td><input type="submit" name="cariorderid" value="Search" /></td>
            <td><input type="text" maxlength="15" name="veh" /></td>
            <td><input type="submit" name="carikendaraan" value="search" /></td>
            <td>Nama Sopir</td>
            <td><input type="text" maxlength="15" name="sopir" /></td>
            <td><input type="submit" name="carisopir" value="Cari" /></td>
            <td>Waktu Berangkat</td>
            <td><input type="text" name="tglb" id="datetimepicker" /></td>
            <td><input type="submit" name="cariberangkat" value="Cari" /></td>
            <td>Waktu Pulang</td>
            <td><input type="text" name="tglp" id="datetimepicker2" /></td>
            <td><input type="submit" name="caripulang" value="Cari" /></td>

maybe there’s a way to make it invisible by a button?

How to&Answers:

You want something like this:

// code for only hide
$('#hide_button').on('click', function() {

Demo for hide

and for toggle the form with a single button you can try:

$('#your_button').on('click', function() {

Demo for toggle

According to comment

To prevent the submission:

$('form[name="myform"]').submit(function(e) {
   // Your code

See here for .perventDefault()