I am a starting with flask/html/javascript and I have this issue:
I render a template from python:
return render_template("loading.html", process='abc')
This es the content of loading.html file
<body>
<div class="titulo">
<p>here I see the value of parameter sent {{process}}</p>
</div>
<div class="loader">
</div>
<script>
function navigate() {
window.location.href = 'process_b';
}
fetch('process_a').then(navigate);
</script>
</body>
This small code works fine it executes process_a then process_b but the question is: How can I use the parameter "process" inside the javascript?
I have tried using:
document.getElementById("process").value
but it does not work
Can someone please help me?
Best regards
document.getElementById("process").value
3
Answers
You need to parse the HTML that’s returned from the API.
The value is in the text of a
<p>
tag, not the value of an input.You can inject values for JavaScript like this:
That is for a string. If it is a number, you don’t need the quotes.
It can be achieved by making a small change in the template code as below
I have added
span
tag withid
attribute withvalue = process
which can be now accessed in javascript by using the below code.Hope it solves your issue.