Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Apr 11th, 2006, 1:26 PM   #1
MegaArcon
Programmer
 
MegaArcon's Avatar
 
Join Date: Aug 2005
Posts: 66
Rep Power: 0 MegaArcon is an unknown quantity at this point
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
MegaArcon is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:06 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC