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
106 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
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 

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 4

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sed question 2 85
drawing animated level bar based on numbers 3 97
JQuery serialize and unserialize 8 84
Gmail hacked or spoofed? 10 28
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 …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to implement Singleton Design Pattern in Java.
In this Experts Exchange video Micro Tutorial, I'm going to show how small business owners who use Google Apps can save money by setting up what is called a catch-all email address in their Gmail accounts. By using the catch-all feature, small busin…

777 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