jquery - How to hide and show element before submit form using javascript? -
how hide , show element before submit form using javascript ?
when press button want show id="loading"
, hide id="sub"
before submit form ?
i test code, show id="loading"
, hide id="sub"
not submit form.
how can ?
<form id="myform" name="send_ask" action="xxx.php" method="post"> <input type="text" name="id" value="12345" style=" display: none;"> <button id="sub">send</button> <span id="result"></span> </form> <div id="loading" style=" display: none;">wait</div> <script type="text/javascript"> $("#sub").click( function() { $.post( $("#myform").attr("action"), $("#myform :input").serializearray(), $("#sub").hide(), $("#loading").show(), function(info){ $("#result").html(info); }); clearinput(); }); $("#myform").submit( function() { homecoming false; }); </script>
i suggest utilize $.ajax()
, utilize beforesend
& complete
. example:
$('#myform').submit(function(e){ e.preventdefault(); $.ajax({ url: $("#myform").attr("action"), data: $("#myform :input").serializearray(), type: 'post', datatype: 'html', success: function(data){ $("#result").html(data); }, beforesend: function(){ $("#loading").show() }, complete: function(data){ $("#loading").hide() } }); });
javascript jquery html
No comments:
Post a Comment