Jim
Jim

Reputation: 121

Getting information from a select tag using Python Tornado

I am trying to pass a user selected option from a drop down menu to Python Tornado.

I have the following HTML code:

            <form method="get" action="search">
                <div class="input-group">
                   <input type="text" name="q" style="width:90%" placeholder="Search articles by title, author, keyword..." class="form-control">
                   <select name="searcher" id="searcher" class="selectpicker form-control" style="width: 10%;">
                        <option id ="default">Title, author, abstract</option>
                        <option id ="experiments">Experiments</option>
                        <option id ="pmid">PubMed ID</option>
                        <option id ="reference">Reference</option>
                   </select>
                   <span class="input-group-btn">
                        <input type="submit" class="btn btn-default" value="Search" />
                   </span>
                </div>
           </form>

and the following in my Tornado Get method:

`

q = self.get_query_argument("q", "")
start = self.get_query_argument("start", 0)
option = self.get_body_argument("searcher")

`

I am able to select both q and start, however, the option attribute errors whenever I try to select it.

Upvotes: 0

Views: 832

Answers (2)

rohini gore
rohini gore

Reputation: 21

Try adding this line

action = self.get_argument("searcher")

Upvotes: 0

Ben Darnell
Ben Darnell

Reputation: 22134

In a form with method="get", all arguments are sent in the query. Use get_query_argument("searcher") instead of get_body_argument("searcher").

Upvotes: 1

Related Questions