- This topic is empty.
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
› Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 9: Flask › Week 9 Froshims: Why failure despite name and sports chosen
Week 9 Froshims: Why failure despite name and sports chosen
byu/DigitalSplendid incs50
Comment
byu/DigitalSplendid from discussion
incs50
ChatGPT:
The suggestion from Reddit is correct. When submitting a form, the <option> tags within a <select> element need a value attribute to pass data when the form is submitted. Currently, your <option> tags only contain the display text ({{ sport }}), but they need a corresponding value that will be submitted with the form. Here’s how you can modify your code to include the value attribute:
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”no” line-numbers=”yes” bg-color=”#abb8c3″ theme=”dark” language=”markup” wrapped=”yes” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
{% extends "layout.html" %}
{% block body %}
<h1>Register</h1>
<form action="/register" method="post">
<input autocomplete="off" autofocus name="name" placeholder="Name" type="text">
<select name="Sport">
<option disabled selected value="">Sport</option>
{% for sport in sports %}
<option value="{{ sport }}">{{ sport }}</option>
{% endfor %}
</select>
<button type="submit">Register</button>
</form>
{% endblock %}
[/dm_code_snippet]
