samedi 23 juillet 2016

python use of html select option value tag

I have been trying to figure this out for a while of how get python to use the selected "value" attribute of the option tag when a user selects from a dropdown list.

If i'm using a dropdown with the select tags name attribute called "height"; when the user select his/her height from the dropdown, I want to grab that selected value attribute and be able to use it in a conditional statement.

     <!-- PATIENT GENDER DROPDOWN TAGS -->
            <select class="select_option" name="gender" id="gender_select">
                <option value="na">Select Patient Gender</option>
                <option value="Male">Male</option>
                <option value="Female">Female</option>
            </select>

Let's say I want the option value "Female", how do I get that value and still differentiate between using select tags "name" attribute to output the user selection and extrapolate the value for other use in a conditional statement.

For instance:

    # Comment.
    def __init__(self):

        # Comment.
        self.first_name = ''
        self.last_name = ''
        self.gender = ''
        self.__age = 0

self.gender is the python attribute to which triggers the HTML dropdown that when selected by the user, outputs "Female" by its HTML "name" attribute. I'm looking to pull the "value" attribute of the user selected "option" HTML tag.

Keep in mind that I do understand that I can't just create self.value in python and expect it to pull the selected HTML "value" attribute, it would not happen.

How would I make this happen?

I would like to use that "value" collected to incorporate it into a python conditional statement, or even a for loop maybe.

I don't expect anyone the write the code for me. I just want to be shown the code that will retrieve that selected "value".

Aucun commentaire:

Enregistrer un commentaire