Hide Form Using JavaScript April 14, 2023 Post a Comment Javascript: function next(a) { if(a==1) { document.getElementById('form1').style.display='none'; } } HTML: Solution 1: You need to use return false <form onsubmit="return next(1)" action="add.php" method="post" id="form1"> Copy Then function next(a) { if(a==1){ document.getElementById("form1").style.display="none"; return false; } } Copy FIDDLE DEMO UPDATE: To Show the form <input type="Submit" value="Show" class="button" onclick="return showForm()" name="show"/> function showForm() { document.getElementById("form1").style.display="block"; return false; } Copy Solution 2: If you want the form to submit and are not plann9ing to use AJAX, you need the PHP to do the hiding when reloading the pageBaca JugaPhp Pass In $this To Function Outside ClassPhp Constant Inside Js FileHow To Display Information When Option Changes? if(isset($_POST['b1'])) { // name of your submit button $hide = true; ?> <input type="button" id="button1 value="click to show form again" /> <? } ?> <form id="form1" class="<? echo $hide?"hidden":"shown";?>"></form> Copy and add $(function() { $("#button1").on("click",function() { $("#form1").prop("class","shown"); }); }); Copy plus a css .hidden { display:none } .shown { display:block } Copy Share You may like these postsJquery Incrementing A Cloned Elements Instead Of Cloned DivWhy Does Variable 'name' Doesnt Need To Be Initialized After First Use [javascript]How To Do Panning In Html5-audio/mozilla Audio Data ApiAlternative Image When Flash Banner Is Not Available Using Html/css? Post a Comment for "Hide Form Using JavaScript"
Post a Comment for "Hide Form Using JavaScript"