javascript - Jquery set different input text and value -
right i'm using $.val() set input's value. want user see different text in input, , still send value set val() server. tried using $.text() doesn't work. there way set html value attribute , set distinct text inside input th## heading ##e user see?
i'm not posting code because pretty generic. reason need because want display nice date string in text (i'm using datetime picker) , send compacted version of string server.
edit
ok, hope helps:
<input class="form-control date" id="booking_time" name="hour" type="text"> in javascript have like:
var date_booked = new date() $("#booking_time").val(date_booked.todatestring()); but want input's value sent server date whithout todatestring proccessing, , still show date.todatestring() in text box. that, hoped work:
$("#booking_time").val(date_booked); $("#booking_time").text(date_booked.todatestring()); but doesn't.
you can try storing date want send server in variable , hook click event of form's submit button change value right before submitting so:
var date_booked = new date() $("#booking_time").val(date_booked.todatestring()); $("#id-of-submit-button").on("click", function() { $("#booking_time").val(date_booked); }); the problem if user edits input overwrite edit , send variable instead. around can use variable detect change in input:
var submitvardate = true; var date_booked = new date() $("#booking_time").val(date_booked.todatestring()); $("#id-of-submit-button").on("click", function() { if (submitvardate) { $("#booking_time").val(date_booked); } }); $("#booking_time").on("change", function() { submitvardate = false; });
Comments
Post a Comment