javascript - Form Submitting Button Not Working When using jQuery hide/show function -
i have form , users can show/hide using jquery.
problem : after user click show/hide (arrow icon) form submission work only 1 time. mean after when click form submit button not working.
what found : seems having '#' in url related problem.
how solve issue?
jsfiddle : https://jsfiddle.net/damithruwan1234/t795ewx3/2/ (you can't test because jsfiddle not allow method )
full code :
<!doctype html> <html lang="en"> <head> <title>bootstrap example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfxpqpzzvqgk6tah5pvlgofqnhsod2xbe+qkpxcaflneevoeh3sl0sibvcoqvnn" crossorigin="anonymous"> <script> $(document).ready(function(){ $("#hide_search").click(function(){ $("#search_panel").hide(1000); $("#show_search").show(); $("#hide_search").hide(); }); $("#show_search").click(function(){ $("#search_panel").show(1000); $("#show_search").hide(); $("#hide_search").show(); }); }); </script> </head> <body> <div class="container"> <h2>vertical (basic) form</h2> <div class="col-sm-8 col-sm-offset-2" id="search_panel"> <form action=""> <div class="form-group"> <label for="email">email:</label> <input type="text" class="form-control" id="email" value="dfdf" placeholder="enter email" name="email"> </div> <div class="form-group"> <label for="pwd">password:</label> <input type="text" class="form-control" id="pwd" value="ssds" placeholder="enter password" name="pwd"> </div> <div class="checkbox"> <label><input type="checkbox" name="remember"> remember me</label> </div> <input type="submit" class="btn btn-info" value="search"> </form> </div> </div> <div class="col-sm-8 col-sm-offset-2"> <a href="#" id="hide_search"> <span class="fa-stack fa-lg"> <i class="fa fa-circle fa-stack-2x"></i> <i class="fa fa fa-angle-up fa-stack-1x fa-inverse"></i> </span> </a> <a href="#" id="show_search" style="display: none;"> <span class="fa-stack fa-lg"> <i class="fa fa-circle fa-stack-2x"></i> <i class="fa fa fa-angle-down fa-stack-1x fa-inverse"></i> </span> </a> </div> </body> </html>
add preventdefault()
on hide/show click event. use below modified script. (the actual issue when click hide/show button add '#' on url, why unable submit form using 'get' method)
$("#hide_search").click(function(e){ e.preventdefault(); $("#search_panel").hide(1000); $("#show_search").show(); $("#hide_search").hide(); }); $("#show_search").click(function(e){ e.preventdefault(); $("#search_panel").show(1000); $("#show_search").hide(); $("#hide_search").show(); });
Comments
Post a Comment