Flask: update form value at JavaScript code
2021. 8. 14. 23:35ㆍFrontend/Web programming
- 목차
반응형
A form can be updated wih the new value at JavaScript code by accessing the form's id through DOM tree element.
<form method="post" action="">
{{ form.hidden_tag() }}
<fieldset class="form-group">
<div class="form-group row">
<div id="id_form_name" class="col-xs-2">
{{ form.name.label(class="form-control-label") }}
...
in the HTML code, name form has its DOM element id as 'name'.
Thus, in the JavaScript code, 'name' is used as DOM element id.
function update_info(data) {
document.getElementById('name').value = data.name
...
}
$.ajax({
type : "POST",
url : ...
dataType: "json",
data: JSON.stringify(selected_row_data),
contentType: 'application/json',
success: function(data) {
update_info(data["_info"])
},
error: function(xtr, status, error) {
console.log("error @ ajax call")
}
});
반응형
'Frontend > Web programming' 카테고리의 다른 글
TypeScript (0) | 2021.12.05 |
---|---|
Update values of the Flask forms in JavaScript section (0) | 2021.09.02 |
JavaScript, HMLT: changing color of selected row in table (0) | 2021.08.14 |
JavaScript: AJAX call w/ Flask (0) | 2021.08.14 |
JavaScript "Failed to find a valid digest in the 'integrity' attribute ..." (0) | 2021.08.13 |