[Tutor] html and mod_python

Adam Cripps kabads at gmail.com
Thu Mar 23 07:29:42 CET 2006


On 3/23/06, Patty <patriciap.gu at gmail.com> wrote:
> Hi!
>
> I created a form in a python file that takes values selected from 6 different
> drop down boxes:
>
> for target in all_targets:
>        s = s + "<form action='process_info' method='POST'>"
>        s = s + "<input type='hidden' name='tg' value=%s>" % target
>        s = s + "<tr><td></td>"
>        for host in hosts:
>            if target in ants_map[host]:
>                s = s + printbox()
>            else:
>              s = s + printemptybox()
>        s = s + """<td><input type='submit' value='Submit'></td></tr>"""
>        s = s + "</form>"
>
> My printbox method contains the following:
> def printbox():
>
>    tag = """
>    <select name="percent">
>    <option VALUE="-">-</option>
>    <option VALUE="0">0%</option>
>    <option VALUE="10">10%</option>
>    <option VALUE="20">20%</option>
>    <option VALUE="30">30%</option>
>    <option VALUE="40">40%</option>
>    <option VALUE="50">50%</option>
>    <option VALUE="60">60%</option>
>    <option VALUE="70">70%</option>
>    <option VALUE="80">80%</option>
>    <option VALUE="90">90%</option>
>    <option VALUE="100">100%</option>
>    </select>"""
>    return tag
>
> When the values are entered, my program stores them into a database.
> Everything worked well, but now I have been asked to retain the values
> selected in the drop down boxes. This means that when I open the web page, the
> drop down boxes should display the recent values entered. I'm not sure how to
> do it, and I'm really hoping that someone can point me to the right direction.
>
> Thanks,
> Patty
>

I've just done something similar with a radio button.

You will need to query your database to find the value.  Then with
that value, you can have a series of 'if' statements which print the
particular option selected if it equals that value.

More than likely, there's a much more efficient way to do it than
this, but this worked for me. I'd be interested to hear if there were
any other ways.

HTH
Adam
--
http://www.monkeez.org
PGP key: 0x7111B833


More information about the Tutor mailing list