I have a form with a method post, but I have to encrypt some of the parameters to md5 before I post them in my javascript. How do I bind the values to that form.
html form:
<input id="sig" name="signature" >signature <i class="fa fa-usd" aria-hidden="true">
</i></br>
javascript:
vm.sig_md5 = $.md5('value');
Use jQuery .submit()
to modify the value at the time of form submission (value is modified before submit, then submit continues).
HTML:
<form action="somewhere.php" method="post">
<input id="sig" name="signature" >signature <i class="fa fa-usd" aria-hidden="true"></i></br>
</form>
jQuery/javascript:
$(document).ready(function(){
$('form').submit(function(){
var sig = $('#sig').val();
sig_md5 = $.md5(sig);
$('#sig').val(sig_md5);
});
});
You can use getter if you don't care about IE<=9
var data = {}
Object.defineProperty(data, 'signature', {
get: function() { return document.getElementById('sig').value; },
set: function(value) { /* set input value hereif needed */ }
})
read more on MDN
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With