This issue caused a lot of controversy in the office, but we came up with a solution.
Use the click button to submit the form (instead of the usual submit button). Then fill in your hidden field, delete the value of the visible field and send. JSFIDDLE
Select a sample event:
$('#post').click(function(e) { var password = $("#password"); var realPassword = $("#therealdeal"); realPassword.val(password.val()); password.val(''); $('#form').submit(); });
It appears that in the submit event, the browser will serialize the form and use the values โโof serlized objects to submit. That's why you can't just do something like
The sample does not work:
$('#form').submit(function(e) { var password = $("#password"); var realPassword = $("#realpassword"); realPassword.val(password.val()); password.val(''); });
even though the value on dom is cleared before the true transfer occurs, it is still read from the object with the serialized form.
Tested in IE, Firefox and Chrome
source share