javascript - Use a button for two functions -- show content, and submit -
i have bootstrap 3 form, shown using it's collapse()
function on <button>
element. then, 1 time form open, have same button become submit button on form. however, have no thought how alter button's function on second press.
example code:
<form class="collapse" id="1234"> <div class="form-group"> <input class="form-control" type="text" placeholder="name"> </div> <div class="form-group"> <input class="form-control" type="email" placeholder="email"> </div> </form> <button class="btn btn-default btn-block" data-toggle="collapse" data-target="#1234">open form</button>
jquery function ready code:
$(".btn-block").click(function () { if ($.trim($(this).text()) == "open form") { $(this).text("submit form"); } else { $(this).text("open form"); } });
here jsfiddle toggle in action: http://jsfiddle.net/tzosozwv/
thanks in advance.
call submit()
on form
element within if
statement:
if ($.trim($(this).text()) == "open form") { $(this).text("submit form"); } else { // presumably want form submitted... $('form#1234').submit(); $(this).text("open form"); }
javascript jquery html twitter-bootstrap
No comments:
Post a Comment