'HTML - Flask - open a new page on button click without using Javascript
I have a table with a feature to select value of a row to send it to the Flask backend, that on button click also redirects my users to a different endpoint. What I need is to open the new endpoint requested in a new webpage instead of the same page. My HTML code where the button is located is as follows. It envelopes a table column value.
{% for item in rows %}
<tr>
<td>{{ item[0] }}</td>
<td>
**<button** formaction="/stockpopup"
type="submit" name = 'stock' value = {{`item[11] }}>
{{ item[11] }}**</button>**
</td>
<td>{{ item[1] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
I am looking for possible alternates to using JavaScript to achieve this outcome if anyone can help.
Solution 1:[1]
You can use the onclick method inside of html.
Something like this should work:
<button onclick="window.open('https://stackoverflow.com','_blank')">Open in new tab</button>
Solution 2:[2]
In your code you are assigning the return value of the print command to com
com = print(handsigns[0])
print in this case returns 'None', so that's what com will get assigned.
Try to print the value of com as a debugging step to see the value.
Additionally, handsigns is a list of the 3 display variables you defined above.
handsigns = [rock, paper, scissors]
Your if statement will never really work out. 'com' will end up being one of the the big docstring values you defined, not the string 'rock'
if com == 'rock':
Consider using one variable set for logic, and one for display:
choices = ["rock", "paper", "scissors"]
# get user choice, display a hand symbol for it.
com = random.choice(choices))
# have computer's choice display a hand symbol for it.
# compare user choice and com choice for message about win lose draw.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 |
