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
101 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 82

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 82

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
How does your email signature look on mobiles?

Do your employees use mobile devices to reply to emails? With mobile becoming increasingly important to the business world, it is in your best interest to make sure that your email signature looks great across all types of devices.

 

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 82

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I didn’t use eM Client for long when I decided to swap to Outlook 2016. The reason for the switch is that it started asking for payment to continue some of its services after one month.   The problems I faced when I didn’t pay were:   I was not …
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now