'Unable to get the value from the drop down from html to python program in flask

I fetch the data from Mysql and populate the values to my html form in a drop down menu.Once the user selects the option, the value which gets sent back is only the first word. For eg. from the drop down , if I choose the value " This is fun " . the first word "This" is only getting passed back to the program. This is for a python flask assignment Code from program:

@app.route('/updateissue',methods=["POST"])
def updateissue():    
      if request.method=='POST':
         if request.form['submit-button'] == 'Update':
             upd1 = request.form.get("updname")
#             upd1 = request.form['updname']
             display(upd1)
             updname = request.form.get("updissue")
             display(updname)
             cursor = conn.cursor()
             cursor.execute('UPDATE issuedb set resolution = %s where issuename = %s', (updname,upd1))
             conn.commit()
             return render_template("close.html")

Code from template:
<div class="row">
                Choose Your Outstanding Issue from the below
            </div>
            <br></br>
            <div class="row">
                <form method="POST" action={{url_for('updateissue')}}>
                <SELECT name="updname" style="font-family:verdana">
                {% for j in upd %}
                <OPTION value={{j[0]}}>{{j[0]}}</OPTION>
                {% endfor %}
                </SELECT>
                <br></br>
                <textarea name="updissue" placeholder="Enter the Resolution"></textarea>
                <input type="Submit" name="submit-button" value = "Update">
                </form>
            </div>

I need the entire value to be passed to my program that is " This is fun".

contents : This is a new issue which you need to find a solution

The route used is below

@app.route('/update')
def update():
      cursor = conn.cursor()
      cursor.execute('SELECT issuename FROM issuedb where resolution is NULL')
      upd = cursor.fetchall()
      return render_template("update.html", upd=upd)

Basically I read the values from the database and populate them to a SELECT clause.Once the user selects the value from the drop down , I send the selected value back to the program for further processing.

Sorry still face the same issue. It is not pulling the whole string.infact while coding just j instead of j[0], the single quotes also gets displayed in the drop down.

It does display the whole string "This is a new issue which you need to find a solution" as such.I see no issues here.

Since I read from the database to populate the drop down combo box, there are multiple values to be displayed on the drop down box.So, I have to use the %for loop to populate these values in the drop down box.When i tried to use your code , all the individual values were getting listed on the same row. This is the input screen enter image description here

Hope you are able to see the screen. The user has to select any of the the 3 values from the drop down.when the second and third row is selected , only the first word is being passed to the program.For eg.when I choose "This is a new issue...." , the value "This" only gets sent back to the program. Hope this helps.

These are the values which gets dispalyed in upd as required by you. (('f',), ('this is a new issue which you need to find resolution',), ('issuessssss are there',))

Thanks for being so much patient and meticulously following on this.Your code works and I am done. Thanks much and very much appreciated!!



Solution 1:[1]

The problem is that your html attribute value does not accept an argument with words separated by spaces. You would need to enclose it all in quotes as shown:

{% for j in upd %}
  <OPTION value="{{j[0]}}">{{j[0]}}</OPTION>
{% endfor %}

Without the quotes around {{j[0}}, the option's value attribute would only recognise the first word.

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 Patrick Yoder