Link to home
Create AccountLog in
Avatar of camster123
camster123

asked on

I am not allowed to use Javascript . I have to change a CGI web firm HTML select control functions after a user choose an option,

I am not allowed to use Javascript . I have to change a CGI web firm HTML select control functions after a user choose an option,
    Here is the source code:

def output_select(name,options,fields):
    print '<td><select id= "%s" name="%s" value = "selectvalue" class="Required" onchange="usgsChanged(this);" >' %      (name,name)
    output_select_options(name,options,fields);
    print '</select></td>'

def output_select_options(name,options,fields,rc=2):
    selected = fields.get(name,'')
    selected = selected.strip()
    if debug:
      print "SELECTED " + selected
    if len(fields) > 0  and 'phase' in fields: # and fields['phase'] == "1":
      goforit = True
    else:
      goforit = False
    for value,text in options:
        if value==selected or text==selected:
          bar = 'selected="selected"'
        else:
          bar = ""
        print '  <option value="%s" %s>%s</option>' % \
              (value,bar,text)
    if rc == 2:
      print '<script type="text/javascript">document.getElementById(\'%s\').innerHTML = "";</script>'% (name)
      url = os.environ["REQUEST_URI"]
      if debug:
        print url
      url = 'https://eecsappsrv.mit.edu/' + url
      if debug:
        print url
      valuestr =  urlparse(url).query
      if goforit and len(valuestr) > 0:
        fields[name] = urllib.unquote(valuestr)
      output_select_options(name,options,fields,1)

Please suggest to me how to replace the javascript with Python and HTML.
Thank you.
      frankc123
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of camster123
camster123

ASKER

@Dave Baldwin,
          Thank you very much for your expert comment.
           i was wondering if you could share your idea on how to  make the page must be submitted with every change until you are done. Your English is better than mine.
          Thank you .
            @frankc123
First, make a list of all the selections and responses.  Then you have to make a series of pages.  You submit the first one and when you respond from the server it contains the data selected on the first page and the data to be selected for the second page.  In PHP, I would keep track of the selections from each page in Session variables so I could respond with the previous data on each page and send the data on the last page.

It can be kind of complicated because on each page you have to check and see if the data was previously posted and include it in the current request.  That is the only way to include previous selections.  Also, each page must be posted to an intermediate page which collects the information and redirects the user to the next appropriate page.  Without the intermediate page that the user never sees, you will have problems when the user click on the back button.
@Dave Baldwin,
          Thank you very much for your expert comment.
          I believe your expert comment refers to multiple pages.
          My web form has only one page.
          Thank you.
              frankc123
frankc123, unfortunately for you, Dave is spot on.  What you are looking for is client-side interaction.  However, you will need to use a client-side language to achieve that functionality.

The only alternative is to use multiple form pages to achieve a similar result.

If you don't mind, can I ask you why you are unable to use JavaScript?  Are your visitors guaranteed to have JavaScript disabled?  Is it an internal company policy?  Whatever the case, the behavior you seek is not available without using a client-side language.
@Jim Riddles,
        Thank you for your help. I apologize for trying to verify that Mr. Dave Baldwin referred to multiple form pages.

>>If you don't mind, can I ask you why you are unable to use JavaScript?
     The reason is exactly as you stated:  "Are your visitors guaranteed to have JavaScript disabled?"
     Thank you again for your expert comment today.
        frankc123
I am definitely talking about multiple pages.  If you can't use javascript, then every change must have it's own page that is processed on the server.  It may be only one page with javascript but it won't be if you have to do all that on the server instead.