Geek07
New Coder
First of all, I don't any previous experience with Javascript, this is my first webapp.
So I'm creating an webapp to construct an URL based on user input and query result, send it to frontend and I'm trying to open it in a new tab on browser.
I'm using flask to handle with server side and Javascript to open the URL on browser. My main difficult until now it's how to handle with flask variable, I can send it to the html perfectly but I can not set it before on the first 'onclick event', on first execution the flask variable shows empty and it's only setted when the 'onclick=open_new_tab()' ends. Note that flask variable depends on the user input.
Anyone could help me?
index.html:
So I'm creating an webapp to construct an URL based on user input and query result, send it to frontend and I'm trying to open it in a new tab on browser.
I'm using flask to handle with server side and Javascript to open the URL on browser. My main difficult until now it's how to handle with flask variable, I can send it to the html perfectly but I can not set it before on the first 'onclick event', on first execution the flask variable shows empty and it's only setted when the 'onclick=open_new_tab()' ends. Note that flask variable depends on the user input.
Anyone could help me?
index.html:
HTML:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE" />
<title>Search by NIF</title>
<link rel="stylesheet" href="{{ url_for('static', filename='main.css')}}">
</head>
<body>
<form action= 'home' method="post">
<script type="text/javascript">
function success() {
if(document.getElementById("nif").value == 0 || document.getElementById("nif").value===0) {
document.getElementById('button').disabled = true;
} else {
document.getElementById('button').disabled = false;
}
}
function open_new_tab() {
var data = '{{data}}';
var url = data.replace(/&/g, '&');
return window.open(url, '_blank').focus();
}
</script>
{% for message in get_flashed_messages()%}
<p>{{message}} </p>
{% endfor %}
<br>
<input class='input' oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);" id="nif" aria-label= "NIF" type="number" min="1" maxlength="9" onkeyup="success()" onkeydown="return event.keyCode !== 69" name="nif_input" required>
<br>
<button id='button' onclick="open_new_tab()" disabled>Search</button>
</form>
</body>
</html>