Solved

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,

Posted on 2014-11-25
7
108 Views
Last Modified: 2015-08-10
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
0
Comment
Question by:camster123
  • 3
  • 3
7 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 40465925
You can not make it act the same with Python and HTML.  Javascript running in the browser can make changes without reloading the page.  When you user a server-side language like Python, PHP, or ASP, the page must be submitted with every change until you are done.
0
 

Author Comment

by:camster123
ID: 40465966
@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
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40465989
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.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:camster123
ID: 40466723
@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
0
 
LVL 5

Expert Comment

by:Jim Riddles
ID: 40466944
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.
0
 

Author Comment

by:camster123
ID: 40466998
@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
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40467569
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.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
countHi challenge 25 155
object oriented javascript web form 8 148
wordlen challenge 3 72
Problem to start Neon 20 120
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question