![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programmer
Join Date: Aug 2005
Posts: 66
Rep Power: 0
![]() |
reloading html select boxs...is there a better way?
Hi all!
I'm doing some work with python and forums and I've created an app that will reload previous form data that a user has entered and saved to a file so they may edit it and re-save the changes. Among that data are several select boxs. I found that reloading the values for those were trickey and the method I used was cluckey and large. I was wondering if anybody knew a more intelegent/elegant way of doing this. Basically, I've sucked the value back down from the file and, depending on it's value built a html string that will have the value selected. Then I print out the page with that string. Likea so: .
.
.
#loaded from xml file
theValue = n.childNodes[0].nodeValue
#html string to be the reloaded select box
htmlString = """
Please select one:
<select>
<option value="1"
"""
if (theValue == "1"):
htmlString = htmlString + """ selected="selected">1</option>
<option value="2">2</option>
"""
else:
htmlString = htmlString + """ >1</option>
<option value="2" selected="selected">2</option>
"""
print myPage % {'select': htmlString}I did out this example with only two values, but I'm actually doing it for a 24 hr clock, thus there are 24 values for the hour method and then another 7 for the minutes (increments of 10). So, as you can imagine, the code gets really big really fast. Any thoughts? I hope my example is clear enough. Thanks. ![]()
__________________
Isn't that just the way life goes? If it's worth doing, it's NP-Hard. Todd Wareham - Memorial University of Newfoundland |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|