python - How would I make my page choose between getting data from a drop-down menu or a text-field? -


thanks yesterday stackoverflow, i've made progress in code. have question, concerning page. here code

#!/usr/bin/python print 'content-type: text/html\n' print  #may 17 import cgi, cgitb cgitb.enable()  form=cgi.fieldstorage()  #may19 dataset1=open('book1.csv','r') dataset2=open('race demographic state.txt','r')  sources='''<hr><h4>sources!</h4><a     href="http://en.wikipedia.org/wiki/demographics_of_the_united_states">race demographics</a> <a href="http://voices.yahoo.com/average-sat-scores-state-2010-7702520.html?cat=4">sat     scores</a> <a href="http://lisa.stuy.edu/~keiran.carpen/briansdirectory/sat scores     state.txt">sat scores txt file</a> <a href="http://lisa.stuy.edu/~keiran.carpen/briansdirectory/race demographic     state.txt">race demographics txt file</a></body></html>'''  def datasplitter(x):     data = x.read()     return data.split("\n")   def datdatamang(x):     data = datasplitter(x)     index = 0     whilenumber = 0     while index < len(data):         whilenumber = 0         string = data[index]         string.split(" ")         x=''         while whilenumber < len(string):             if string[whilenumber] == ',':                 x=x+'</td><td>'             else:                 x=x+string[whilenumber]             whilenumber+= 1         ' '.join(string)         data[index]='<tr><td>'+x+'</td></tr>'         index+=1     result=' '.join(data)     result='''<table border='1'>'''+result+'</table>'     return result  #may 19 def getdescription():     page = ''     state = '' #may20     if 'drop' in form:         if form['drop'].value =="description":             page+= 'ever since conception, sat examinations have been     controversial.many individuals believe race intellectually superior,     , sat scores reflect on superiority. job find     correlation between scores , race , end battle among races!'         if form['drop'].value=="high sat scores":             page+= datdatamang(dataset1)         if form['drop'].value=="race demographics":             page+= datdatamang(dataset2)         if form['drop'].value=="source":             page+= sources         else:      return page  #may 21 def getstate():     table=''     if 'on' in form:         state+= form['on'].value     if state in dataset1:         state.header=dataset1.index(state)         n in dataset1[state.header]:             table+='''<tr>'''+n+'''</tr>'''         return '''<td>'''+table+'''</td>'''   def getracebystate():     if 'on' in form:         state+= form['on'].value     if state in dataset2:         state.header=dataset2.index(state)         n in dataset2[state.header]:             table+='''<tr>'''+n+'''</tr>'''         return '''<td>'''+table+'''</td>'''     #may 20 print '''<html><title>sat analysis</title>''' print '''<body>''' print getdescription() print '''</body></html>'''    #may 17 - writing analysisv2.html file , starting code #may 19 - tables, , #may 20 - writing if statements drop-down menu, building page. #may 21 - working on text fields , getstate 

essentially, page works have drop-down menu choose (choosing 1 of these values: e.g. "high sat scores" , "race demographics" causes python code generate page tables, or descriptions concerning drop-down menu option), or text field (which searches state in csv files, , returns table-row data particular state). using cgi.fieldstorage() python collects value submitted through html form. however, how write code send value text-field only, through html form.

i.e. if not want use drop-down menu, , instead want use text-field find state in particular , not submit form data through drop-down menu, how do that?

i not sure whether missing here but, assuming 'on' name of text field, can check see whether text field empty so:

if 'on' in form , form['on']:     dosomethingwithon() else:     dosomethingwithdrop() 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -