javascript - Keep jquery option value, save user's value -
i'm trying achieve quite small. i'll try best explain it.
i have option form multiple selects, year, month , date. whenever user selects something, form submitted can fetch data database.
<form role="form" action="" method="post"> <select class="form-control" id="day" name="day" onchange="this.form.submit()"> <option>- dummy option -</option> <option>- dummy option -</option> <option>- dummy option -</option> <option>- dummy option -</option> </select> </form>
one day, month , year.
element's ids "day", "month", "year"
.
i'm trying show today's date default, automatically fetches today's information.
as i'm relatively new js/jq, i've tried set options today's date :
var fyear = currentdate.getfullyear(); var fmonth = currentdate.getmonth()+1; var fday = currentdate.getdate(); $("#year").val(fyear); $("#month").val(fmonth); $("#day").val(fday);
problem whenever user selects option, keeps re-appending today's date, overriding user's selection.
-- question --
how go showing today's date when user hasn't done select form? show date if form hasn't been changed user.
thank you.
i believe want use jquery.ajax allow submit form without refreshing page.
assuming page called page.html
, html looked -
<form id="myform" role="form" action="" method="post"> <select class="form-control" id="day" name="day" onchange="this.form.submit()"> <option>- dummy option -</option> <option>- dummy option -</option> <option>- dummy option -</option> <option>- dummy option -</option> </select> </form>
your javascript should like
$("#myform").submit(function(event){ event.preventdefault(); $.ajax({ type: "post", url: "page.html", data: $(this).serialize(), success: function (result) { ..... result }, error: function() { ..... report error } });
Comments
Post a Comment