In html template I have 3 fields (defined in models.py): A, B and C
. It is a form. I want field C
to have a sum of A + B
when user types some value.
Is that something I can do with python or it is necessary JavaScript?
You will have to use JavaScript since it's in the front-end. Setup a jQuery listener so that once elements A & B are modified the value C is also modified.
$('#A, #B').on('input',function(e){
$('#C').val(parseInt($('#A').val()) + parseInt($('#B').val()));
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.